# Token visible in Javascript

**URL:** <https://community.dynatrace.com/t/token-visible-in-javascript/46047>\
**Category:** Automations\
**Tags:** workflows, automations\
**Created:** [June 11, 2024, 11:44am UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047 "2024-06-11T11:44:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [June 11, 2024, 11:44am UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/1 "2024-06-11T11:44:41Z")

</div>

Hello All,

I notice you can see the value of a token when used in Javascript, I assume that this is inherent to the used implementation? Or will there be an improvement?

KR Henk

 ![henk_stobbe_0-1718106034452.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/2/02582ff2d4e98822c616da82cb5df305847ff926.png)

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [June 11, 2024, 12:43pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/2 "2024-06-11T12:43:53Z")

</div>

Hi! In the screenshot, you’re seeing the Result tab of a “run\_javascript” task. Most likely, the token is returned as part of this task. You can investigate and change this by editing the Workflow, and looking at the “Run JavaScript” task in question, which probably looks something like this:

```javascript
// optional import of sdk modules
import { execution } from '@dynatrace-sdk/automation-utils';

export default async function ({ execution_id }) {
  // your code goes here
  const token = "1234";
  const scope = "SCOPE";

  // do something

  return { token: token, scope: scope };
}

```

edit: now if you’re asking whether you can mask this token, that’s a no for now. What you could however do instead is store the token using [secrets in App-Settings](https://developer.dynatrace.com/develop/data/app-settings/#use-secrets) or [Dynatrace Credential Vault](https://developer.dynatrace.com/reference/sdks/client-classic-environment-v2/#credentialvaultclient).

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [June 11, 2024, 12:51pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/3 "2024-06-11T12:51:12Z")

</div>

Hi Christian,

Sorry, it is returned by below code in the task:

tokenCredentials = await credentialVaultClient.getCredentialsDetails({  
id: ‘CREDENTIALS\_VAULT-04B79924E62A26F3’,

So I was thinking it is the real token value

KR Henk

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [June 11, 2024, 12:55pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/4 "2024-06-11T12:55:24Z")

</div>

Now I see 🙂 The Run JavaScript task is doing exactly what you tell it to do, which, in this case, is returning the **full response** of getCredentialsDetails from credentialVaultClient.

I suppose you want to use the token returned in a follow-up task?

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [June 11, 2024, 1:06pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/5 "2024-06-11T13:06:30Z")

</div>

Absolutely,

So in simple terms, next step would be a POST request using this credential.

My main concern was that I can see the token used in the script, so this would be a security risk as anybody who can see the workflow can possibly see and copy the token?

See my token definition:

 ![henk_stobbe_0-1718111154228.png](https://global.discourse-cdn.com/dynatrace/original/2X/4/4851d3dcab67ed5b295c5a84d6b89c8ce6cfae29.png)

KR Henk

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [June 11, 2024, 1:11pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/6 "2024-06-11T13:11:15Z")

</div>

Yes, that’s all correct. Don’t return the token. Support for using credentials/secrets in a secure way is on the roadmap, as far as I know. For the time being,

For the time being, you can use fetch in the Run JavaScript action like this:

```javascript
const token = await credentialVaultClient.getCredentialsDetails({
    id: "CREDENTIALS_VAULT-ABCD1234",
  }).then((credentials)=> credentials.token);

  const url = "https://....";

  const response = await fetch(url, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${token}`
    }
  ).then(response => response.json());

```

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [June 11, 2024, 1:16pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/7 "2024-06-11T13:16:16Z")

</div>

Cool thx Christain!

---

<div class="post-metadata">

**Author:** ![kuncarlos](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/kuncarlos/32/32091_2.png) [@kuncarlos](https://community.dynatrace.com/u/kuncarlos)\
**Post date:** [May 21, 2025, 1:00pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/8 "2025-05-21T13:00:56Z")

</div>

Hi, is this solution also valid for Managed?

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [May 21, 2025, 1:33pm UTC](https://community.dynatrace.com/t/token-visible-in-javascript/46047/9 "2025-05-21T13:33:15Z")

</div>

Hi!

No, it’s only for SaaS, with DPS.
