CurrentToken

Not available in this language yet.
Not available in this language yet.
CurrentToken()
CurrentToken()
current_token()
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.

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.
System.out.println(
    client.query(
        CurrentToken()
    ).get());
ref(id = "1", collection = ref(id = "tokens"))
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Ref(Tokens(), "1")
result = client.query(
  q.current_token()
)
print(result)
Ref(id=1, collection=Ref(id=tokens))
try {
  println(Await.result(
    client.query(
      CurrentToken()
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
ref(id = "1", collection = ref(id = "tokens"))

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

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        CurrentToken()
    ).get());
ref(id = "1", collection = ref(id = "keys"))
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Ref(Keys(), "1")
result = client.query(
  q.current_token()
)
print(result)
Ref(id=1, collection=Ref(id=keys))
try {
  println(Await.result(
    client.query(
      CurrentToken()
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
ref(id = "1", collection = ref(id = "keys"))

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

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        CurrentToken()
    ).get());
{iss: "https://dev--nozpv3z.us.auth0.com/", sub: "l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients", aud: "https://db.fauna.com/db/yxxf5x9w1ybyn", iat: 1611084659, exp: 1611171059, azp: "l6vJS8QvHC2LmiGRaOTiE16givuufR22", gty: "client-credentials"}
client.query(
  q.CurrentToken()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  iss: 'https://dev--nozpv3z.us.auth0.com/',
  sub: 'l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients',
  aud: 'https://db.fauna.com/db/yxxf5x9w1ybyn',
  iat: 1611084659,
  exp: 1611171059,
  azp: 'l6vJS8QvHC2LmiGRaOTiE16givuufR22',
  gty: 'client-credentials'
}
Not available in this language, yet.
try {
  println(Await.result(
    client.query(
      CurrentToken()
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{exp: 1611171059, iat: 1611084659, sub: "l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients", azp: "l6vJS8QvHC2LmiGRaOTiE16givuufR22", aud: "https://db.fauna.com/db/yxxf5x9w1ybyn", gty: "client-credentials", iss: "https://dev--nozpv3z.us.auth0.com/"}

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!