# How to access Private Keys in client-side Elements

**URL:** <https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364>\
**Category:** Plugins\
**Created:** [June 26, 2024, 2:51am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364 "2024-06-26T02:51:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielkellydev](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@danielkellydev](https://forum.bubble.io/u/danielkellydev)\
**Post date:** [June 26, 2024, 2:51am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/1 "2024-06-26T02:51:29Z")

</div>

Hi all,

I’m creating a plugin that integrates Stripe payments.

Within the Element, the Initialize function initializes Stripe with a provided API key. Currently the keys are set up as Public keys.

![image](https://us1.discourse-cdn.com/bubble/original/3X/1/d/1d0371291e435df596cad794e1c40214388db412.png)

For security, these would obviously be better as Private keys. Though when I set them as Private, I can’t easily access them from my Element.

What would be the most straightforward way to get Private keys into Element code?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![lindsay\_knowcode](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lindsay_knowcode/32/92967_2.png) [@lindsay\_knowcode](https://forum.bubble.io/u/lindsay_knowcode)\
**Post date:** [June 26, 2024, 3:43am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/2 "2024-06-26T03:43:14Z")

</div>

As you’ve figured out, things are not secret when they are exposed in the browser. 🙂

One technique is to have your front end code call a backend workflow. Then any processing requiring secrets is done in that backend workflow.

---

<div class="post-metadata">

**Author:** ![danielkellydev](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@danielkellydev](https://forum.bubble.io/u/danielkellydev)\
**Post date:** [June 26, 2024, 5:08am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/3 "2024-06-26T05:08:29Z")

</div>

Thanks Lindsay.

Can server-side actions access Private keys directly via context.keys?

---

<div class="post-metadata">

**Author:** ![tylerboodman](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tylerboodman/32/242142_2.png) [@tylerboodman](https://forum.bubble.io/u/tylerboodman)\
**Post date:** [June 26, 2024, 5:13am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/4 "2024-06-26T05:13:25Z")

</div>

Yes like this: `context.keys["Stripe Secret Key"]` then the name just has to match in the keys section

---

<div class="post-metadata">

**Author:** ![danielkellydev](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@danielkellydev](https://forum.bubble.io/u/danielkellydev)\
**Post date:** [June 26, 2024, 5:18am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/5 "2024-06-26T05:18:59Z")

</div>

Thanks, I’m going to try this now.

---

<div class="post-metadata">

**Author:** ![danielkellydev](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@danielkellydev](https://forum.bubble.io/u/danielkellydev)\
**Post date:** [June 26, 2024, 7:54am UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/6 "2024-06-26T07:54:37Z")

</div>

Just an update. I created a server-side action that retrieves the private key.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/7/7/77e1d002cdd8b08aa3ff187380c69a778aa8b3e9.png)

Then, created a backend workflow that calls this action, and returns the key.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/9/d/9d96a7fd55874abcc0e78c55f7bf8a35a90598e7.png)

Then, created a property in the Client-side element that takes the endpoint to run the action.

![image](https://us1.discourse-cdn.com/bubble/original/3X/a/9/a9050e791c565f9074919b5f14e12e82a6a90494.png)

Now, this endpoint can be accessed within the Element’s Update function via `properties.publishable_key_endpoint`.

The endpoint can now be used in function Initialize for a POST request to retrieve the STRIPE\_PUBLISHABLE\_KEY.

```
    fetch(publishableKeyEndpoint, {
      method: 'POST'
    })
      .then(response => response.json())
      .then(data => {
        if (data.status === 'success' && data.response && data.response.publishable_key) {
          const publishableKey = data.response.publishable_key;
          instance.data.publishableKey = publishableKey;
          return instance.data.loadStripeScript(publishableKey);

```

And it works!

I’d like to simplify it eventually if possible, but the main thing for now is that it’s working.

---

<div class="post-metadata">

**Author:** ![tylerboodman](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tylerboodman/32/242142_2.png) [@tylerboodman](https://forum.bubble.io/u/tylerboodman)\
**Post date:** [June 26, 2024, 3:30pm UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/7 "2024-06-26T15:30:14Z")

</div>

I haven’t used Stripe, but according to google the Publishable Key isn’t supposed to be a private key, so that you can do directly in your element without all the workarounds since it’s intended for client side use.

The Secret Key is the one you can’t let get exposed

---

<div class="post-metadata">

**Author:** ![Jici](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jici/32/30722_2.png) [@Jici](https://forum.bubble.io/u/Jici)\
**Post date:** [June 26, 2024, 3:35pm UTC](https://forum.bubble.io/t/how-to-access-private-keys-in-client-side-elements/328364/8 "2024-06-26T15:35:06Z")

</div>

PK can be used for client side for some scripts.  
If you need SK, this need to be used server side.  
Not sure what you are doing, but I don’t see any reason to use a server side script where you can use API Connector.
