Key.create()
Create an key.
Description
This method creates a key based on the data parameters. If no database
field is supplied, create()
is associated and grants access to the current
database.
Keys grant anonymous-based access to a database. When create()
is called,
Fauna returns a document width the key secret
field. This field is a
password equivalent. The create()
caller must retrieve the secret
from the
result and store it.
At creation is the only time Fauna displays the secret
field. The value in
this field is equivalent to a password. Fauna cannot recover a secret that
is discarded or lost. Copy and save the secret to a password manager or other
safe location. Delete and replace keys or tokens for which you have lost the
secret. If you no longer need a key or token, you should delete it.
The role
field supplied by the create()
method configures the key
privileges. A key can attach to user-defined roles for attribute-based access
control (ABAC) or to the Fauna built-in roles (admin
, server
,
server-readonly
).
After the key is created, a caller with the key secret
can connect to
Fauna and query the associated database for the privileges associated with
the key role
.
A caller cannot create a key with greater privileges than the key used to make the call.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
data |
Object describing the key. |
data fields
Name | Type | Required | Description |
---|---|---|---|
role |
Yes |
Reference to a role or an Array of roles. Roles can be user-defined
roles or the built-in access roles, |
|
database |
Name of an existing child database. If omitted, the new key grants access to the current database. |
||
priority |
A relative weight between 1 and 500 configuring how many resources this key is allowed to utilize. A higher number indicates more resources. By default, this is 1. |
||
data |
User-defined metadata to store supplemental key information. |
||
ttl |
Timestamp indicating a document lifespan. When the |
Return value
Type | Description |
---|---|
New |
Examples
{
id: "371460335192768546",
coll: Key,
ts: Time("2023-07-28T02:23:51.300Z"),
ttl: Time("2023-07-29T02:23:51.189192Z"),
secret: "fnAFJ7E071AAIs6Y4zxpfDA_NeMOxJw44V3_ZW_g",
role: "mgmtTeam"
}
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!