CurrentToken

Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
CurrentToken()
Not available in this language yet.
Not available in this language yet.

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.

Parameters

None.

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:

Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Ref(Tokens(), "1")
Not available in this language yet.
Not available in this language yet.

The following query runs in the context of a Fauna key:

Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Ref(Keys(), "1")
Not available in this language yet.
Not available in this language yet.

The following query runs in the context of a JWT token:

Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  iss: 'https://dev--nozpv3z.us.auth0.com/',
  sub: 'q6vJS85vH@2LmiGrAOTiE16giVUuFr22@clients',
  aud: 'https://db.fauna.com/db/yxxf5x9w1ybyn',
  iat: 1605502648,
  exp: 1605589048,
  azp: 'q6vJS85vH@2LmiGrAOTiE16giVUuFr22',
  gty: 'client-credentials'
}
Not available in this language yet.
Not available in this language yet.

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!