CreateKey
CreateKey( param_object )
Description
CreateKey
creates a new key, based on the settings in param_object
,
which can be used to access the current database. If you provide an
optional ref to a child database, the key is
associated with (and provides access to) that database. An admin key
must be used when calling CreateKey
.
Once the key is created, the key’s secret can be used to connect to
Fauna and execute queries within the associated database, with the
permissions associated with the key’s role
.
If you would prefer to use Fauna’s
Attribute-based access control (ABAC), you
should use the Login
function instead.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
The |
param_object
Field Name | Field Type | Definition and Requirements | ||
---|---|---|---|---|
|
The access roles include
|
|||
|
Optional - A ref of an existing child database. If not provided, the new key grants access to the current database. |
|||
|
Optional - A name to apply to the key, to help differentiate this key from any others that may exist. |
|||
|
Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this key should be allowed to utilize. Defaults to 1. A higher number means more resources.
|
|||
|
Optional - Contains user-defined metadata for the key. It is provided for the developer to store key-relevant information. |
Returns
An object containing the metadata about the results of CreateKey
operations.
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
The reference is an automatically-generated, unique identifier within the database to the key that was created. |
|
|
The ref of the database that the key belongs to. |
|
|
The access role for this key. |
|
|
The name for this key. Only present when specified during key creation. |
|
|
The timestamp, with microsecond resolution, associated with the creation of the key. |
|
|
The key’s authentication secret. It is only present at creation. You must copy the key’s secret and store it securely for future use. |
|
|
The key’s hashed authentication secret. |
Examples
The following query creates a key for the prydain
database with an
access role of server
.
client.query(
q.CreateKey({
database: q.Database('prydain'),
role: 'server',
})
)
.then((ret) => console.log(ret))
{ ref: Ref(id=200295040051839490, collection=Ref(id=keys)),
ts: 1527275085327966,
database: Ref(id=prydain, collection=Ref(id=databases)),
role: 'server',
secret: 'fnACx5dHGJACAvbi1rpiKJFPsvWEdwvJjmEllT1q',
hashed_secret:
'$2a$05$cNALKjEyHHbx5XcxdQDd1uFlg9w7ILiGCkPiOBm.GkqdRvqLYTJpe' }
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!