Accessing Auth Tokens in APIs
Last updated
Last updated
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.
While creating or updating the Authentication Secret, you can define the schema of the token there itself. For example -
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.
For more details on how to configure Authentication and how to define the decoded token schema, please check this link.
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, such as - $.tokenData.sub
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