# 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="/files/HxchXlodYcDYYrLN4rX2" 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](/flow-builder/cql-cosmocloud-query-language/magical-autocomplete.md), 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`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cosmocloud.io/examples-how-to/accessing-auth-tokens-in-apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
