# Accessing Auth Tokens in APIs

You would have often faced times where you need to read the access token / auth token and read some certain values from the same (such as `user_id`).

To do this, we would first need to configure authentication in Cosmocloud and define the schema of the decoded token - mentioning what parameters can be expected in the token.

## Defining the token schema in Authentication Secret

While creating or updating the Authentication Secret, you can define the schema of the token there itself. For example -

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FkH2UqHV2C9XGD8KAK0BZ%2FScreenshot%202024-05-06%20at%201.06.08%E2%80%AFPM.png?alt=media&#x26;token=f4476b7e-a2ed-4363-96e6-f710db04be4e" alt=""><figcaption></figcaption></figure>

As you can see above, our auth token can have fields such as `sub`, `orgId`, `name` and `age`. We say that `sub` is the field where the user's ID would also be present, hence we add `sub` to `User Id Key` field as well.

{% hint style="info" %}
For more details on how to configure Authentication and how to define the decoded token schema, please check this link.
{% endhint %}

## Accessing token properties in Flow Builder

Now, once we have defined the schema of our token in our Authentication Secret, we can now access these in our Flow Builder using [Magical Autocomplete](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/magical-autocomplete), such as - `$.tokenData.sub`

### Token Properties

You can access any token property you set in the secret using the format - `$.tokenData.<key_name>`.

You can also access the **raw token**, sometimes useful to pass to another API call, using the syntax - `$.tokenData.rawToken`
