FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
Tokens
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Tokens( [database] )
tokens( [database] )
Tokens( )
ScopedTokens( database )
Tokens( [database] )
Tokens( [database] )
Tokens( [database] )
Description
The Tokens
function provides access to the system collection that
stores access tokens, created with the Login
function. This is
useful for:
-
Listing currently existing tokens
-
Creating tokens without credentials
-
Indexing tokens so that you can query tokens based on relationships with other documents.
If you have a reference to a specific token, acquired with Login
, you
can add custom fields to the token’s document using Update
or
Replace
. Access tokens can be invalidated by calling
Logout
.
A token’s instance field contains a Reference to the associated
identity document. See Tokens for details.
|
Parameters
Parameter | Type | Definition and requirements |
---|---|---|
|
Reference |
Optional - A Reference to a child database. If not specified, the current database is used. A Reference to a child database. Optional - A Reference to a child database. If not specified, the current database is used. Optional - A Reference to a child database. If not specified, the current database is used. Optional - A Reference to a child database. If not specified, the current database is used. Optional - A Reference to a child database. If not specified, the current database is used. Optional - A Reference to a child database. If not specified, the current database is used. |
Returns
An Set Reference for the available Tokens in the specified child
database
, or the current database if database
is not specified.
Examples
-
Create a token
The following query lists any existing tokens (up to the pagination limit) in the current database:
{ ref: Ref(Tokens(), "251500495731950080"), ts: 1576108413380000, instance: Ref(Collection("users"), "251407645221585408"), secret: 'fnEDfYJeTPACAAN9IwrU8AIAItH5Pfj5cqbybb_JmqNOncUKI14' }
{'ref': Ref(id=251502661795316224, collection=Ref(id=tokens)), 'ts': 1576110479070000, 'instance': Ref(id=251407645221585408, collection=Ref(id=users, collection=Ref(id=collections))), 'secret': 'fnEDfYRWoGACAAN9IwrU8AIAFwnfIh4vM_28LzJqFIP_45o8X2Q'}
map[instance:{1 0xc00008e510 0xc00008e510 <nil>} ref:{280481975565812224 0xc00008e360 0xc00008e360 <nil>} secret:fnED5Hje54ACAAPkeN55YAYAIveL6bdkDgZ0-2-Eng567vL_H_0 ts:1603747306320000]
ObjectV(ref: RefV(id = "280491974570541568", collection = RefV(id = "tokens")),ts: LongV(1603756842110000),instance: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),secret: StringV(fnED5IH2-qACAAPkgfXLUAYAx7PIdaBJcNJko75-RceyXHxk4PA))
{ref: ref(id = "251501214465786368", collection = ref(id = "tokens")), ts: 1576109098790000, instance: ref(id = "251407645221585408", collection = ref(id = "users", collection = ref(id = "collections"))), secret: "fnEDfYMFpNACAAN9IwrU8AIAci6OvrScKEoSVSpbfZq7_LfCpeA"}
{ ref: Ref(Tokens(), "302044099688530432"), ts: 1624310550300000, instance: Ref(Collection("users"), "1"), secret: 'fnEEMROCJHACAAQxE4GIcAIADYV7pzCKqnsAm8N0nsY1vlCMJYQ' }
You can also create a token directly, without knowing the credentials for an identity document:
{ ref: Ref(Tokens(), "293497693263626752"), ts: 1616160062000000, instance: Ref(Collection("users"), "1"), secret: 'fnEEEraY1WACAAQStphjIAYALk1agYtuTK3v_x8KTSs7bpe2scg' }
{'ref': Ref(id=293498079059902976, collection=Ref(id=tokens)), 'ts': 1616160429920000, 'instance': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'secret': 'fnEEErbyqKACAAQStvIo8AYA8p8sN07-yrVgDzXke1NWRgnqxCc'}
map[instance:{1 0xc00014c270 0xc00014c270 <nil>} ref:{293498065541661184 0xc00014c0c0 0xc00014c0c0 <nil>} secret:fnEEErbvguACAAQStu7jYAIAEIJ3Z3UMa7-cr_-6IVyErFg9ua4 ts:1616160417020000]
ObjectV(ref: RefV(id = "293498062688485888", collection = RefV(id = "tokens")),ts: LongV(1616160414310000),instance: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),secret: StringV(fnEEErbu2NACAAQStu1CoAIAR6v4yT6ii450sVhEfdcttH3eLhE))
{ref: ref(id = "293498073803391488", collection = ref(id = "tokens")), ts: 1616160424910000, instance: ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections"))), secret: "fnEEErbxb1ACAAQStu-OYAYA14OfYlj7hD7jbg8uI73gZGZHp3g"}
{ ref: Ref(Tokens(), "302044084418118144"), ts: 1624310535730000, instance: Ref(Collection("users"), "1"), secret: 'fnEEMRN-lkACAAQxE33O0AYA3fbFMCO_kONC35tJ2tPZIMoJ4Lc' }
When you create a token directly, you can also set its
ttl
(time to live):{ ref: Ref(Tokens(), "294155374728053248"), ts: 1616787275910000, instance: Ref(Collection("users"), "1"), ttl: Time("2021-03-28T19:34:35.900Z"), secret: 'fnEEFQzBO3ACAAQVDMDIIAYAvxbzRoRT6Tax-k8N9fGhR2ledDk' }
{'ref': Ref(id=294155377506779648, collection=Ref(id=tokens)), 'ts': 1616787278560000, 'instance': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'ttl': FaunaTime('2021-03-28T19:34:38.550Z'), 'secret': 'fnEEFQzB4RACAAQVDMFlQAYAGniNtprOy79A7nWPQ8TVJfD-6zg'}
map[instance:{1 0xc000184660 0xc000184660 <nil>} ref:{294155364114366976 0xc0001844b0 0xc0001844b0 <nil>} secret:fnEEFQy-wtACAAQVDL37gAIADRiIr6AEwLSUV0A7XJJCKJO32x8 ts:1616787265790000 ttl:{780000000 63752556865 <nil>}]
ObjectV(ref: RefV(id = "295343068397175296", collection = RefV(id = "tokens")),ts: LongV(1617919948860000),instance: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),ttl: FaunaTime(2021-03-28T19:34:28.857Z),secret: StringV(fnEEGUT0trACAAQZRPNp4AYAK_7_A4jRa6iPR5LJIRhzT8NIxYU))
{ref: ref(id = "294155372234539520", collection = ref(id = "tokens")), ts: 1616787273540000, instance: ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections"))), ttl: 2021-03-28T19:34:33.528Z, secret: "fnEEFQzAptACAAQVDL7JYAYAzLPtSdFzHxT2a4WYjMbHi4OhB9I"}
{ ref: Ref(Tokens(), "302044087434871296"), ts: 1624310538620000, instance: Ref(Collection("users"), "1"), ttl: Time("2021-06-23T21:22:18.607Z"), secret: 'fnEEMRN_ShACAAQxE36hQAYAWLgKxjGircfBLeB5z-IGW4eZU_Y' }
-
List existing tokens
{ data: [ Ref(Tokens(), "255391018093904394") ] }
{'data': [Ref(id=1, collection=Ref(id=tokens))]}
map[data:[{1 0xc0000b7230 0xc0000b7230 <nil>}]]
ObjectV(data: Arr(RefV(id = "1", collection = RefV(id = "tokens"))))
{data: [ref(id = "1", collection = ref(id = "tokens"))]}
{ data: [ Ref(Tokens(), "1") ] }
The following query lists the References for any tokens (up to the pagination limit) in a child database named "child_db":
{ data: [] }
{'data': []}
map[data:[]]
ObjectV(data: Arr())
{data: []}
{ data: [] }
-
Use
Tokens()
in an indexThe following query creates an index on the internal tokens collection, so that tokens associated with a specific service can be queried:
{ ref: Index("tokens_by_instance"), ts: 1592112574490000, active: true, serialized: true, name: 'tokens_by_instance', permissions: { read: 'public' }, source: Tokens(), terms: [ { field: 'instance' } ], values: [ { field: [ 'data', 'name' ] } ], partitions: 1 }
{'ref': Ref(id=tokens_by_instance, collection=Ref(id=indexes)), 'ts': 1592867275570000, 'active': True, 'serialized': True, 'name': 'tokens_by_instance', 'permissions': {'read': 'public'}, 'source': Ref(id=tokens), 'terms': [{'field': 'instance'}], 'values': [{'field': ['data', 'name']}], 'partitions': 1}
map[active:true name:tokens_by_instance partitions:1 permissions:map[read:public] ref:{tokens_by_instance 0xc00008e210 0xc00008e210 <nil>} serialized:true source:0x15326c0 terms:[map[field:instance]] ts:1603747302540000 values:[map[field:[data name]]]]
ObjectV(ref: RefV(id = "tokens_by_instance", collection = RefV(id = "indexes")),ts: LongV(1603756832100000),active: BooleanV(True),serialized: BooleanV(True),name: StringV(tokens_by_instance),permissions: ObjectV(read: StringV(public)),source: RefV(id = "tokens"),terms: Arr(ObjectV(field: StringV(instance))),values: Arr(ObjectV(field: Arr(StringV(data), StringV(name)))),partitions: LongV(1))
{ref: ref(id = "tokens_by_instance", collection = ref(id = "indexes")), ts: 1594335339530000, active: true, serialized: true, name: "tokens_by_instance", permissions: {read: "public"}, source: ref(id = "tokens"), terms: [{field: "instance"}], values: [{field: ["data", "name"]}], partitions: 1}
{ ref: Index("tokens_by_instance"), ts: 1624310541660000, active: true, serialized: true, name: 'tokens_by_instance', permissions: { read: 'public' }, source: Tokens(), terms: [ { field: 'instance' } ], values: [ { field: [ 'data', 'name' ] } ], partitions: 1 }
-
Modify a token
In the following query, we use an existing token’s reference to update the token with some metadata:
{ ref: Ref(Tokens(), "251500495731950080"), ts: 1576108413460000, instance: Ref(Collection("users"), "251407645221585408"), data: { meta: 'data' } }
{'ref': Ref(id=251502661795316224, collection=Ref(id=tokens)), 'ts': 1576110479090000, 'instance': Ref(id=251407645221585408, collection=Ref(id=users, collection=Ref(id=collections))), 'data': {'meta': 'data'}}
map[data:map[meta:data] instance:{1 0xc000174270 0xc000174270 <nil>} ref:{1 0xc0001740c0 0xc0001740c0 <nil>} ts:1603747308150000]
ObjectV(ref: RefV(id = "1", collection = RefV(id = "tokens")),ts: LongV(1603756847050000),instance: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),data: ObjectV(meta: StringV(data)))
{ref: ref(id = "251501214465786368", collection = ref(id = "tokens")), ts: 1576109098880000, instance: ref(id = "251407645221585408", collection = ref(id = "users", collection = ref(id = "collections"))), data: {meta: "data"}}
{ ref: Ref(Tokens(), "1"), ts: 1624310552760000, instance: Ref(Collection("users"), "1"), data: { meta: 'data' } }
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!