CurrentToken
CurrentToken()
Description
The CurrentToken
function returns information about the active
authentication:
-
When a token is used, a Reference to the token document is returned.
-
When a key is used, and the key exists in the current database (and not in a parent database), a Reference to the key document is returned.
-
When authentication is performed by an identity provider, an object containing the active JWT’s claims is returned.
For all other cases, CurrentToken
emits an error. These cases include:
-
Authentication uses the "root" Fauna secret.
-
Authentication uses a key that has the
database
field set. -
Authentication uses a key that exists in a parent database, for example, when using a scoped key.
Returns
For tokens, and keys defined in the current database, a Reference to the associated token/key.
For JWTs, an object containing the claims from the active JWT.
For connections using the "root" Fauna key, or a key that has the
database
field defined, an error is returned.
Examples
-
The following query runs in the context of a Fauna token:
Ref(Tokens(), "1")
-
The following query runs in the context of a Fauna key:
Ref(Keys(), "1")
-
The following query runs in the context of a Fauna key defined in a parent database:
Copied!The Shell version of this example is not currently available.
-
The following query runs in the context of a JWT token:
{ iss: 'https://dev--nozpv3z.us.auth0.com/', sub: '8cYrAhHUTtqr9eSliRmdrGryJhYbcPQA@clients', aud: 'https://db.fauna.com/db/yo8yrjgkcydye', iat: 1624306581, exp: 1624392981, azp: '8cYrAhHUTtqr9eSliRmdrGryJhYbcPQA', gty: 'client-credentials' }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!