KeyFromSecret
KeyFromSecret( secret )
f.KeyFromSecret( secret )
KeyFromSecret( secret )
KeyFromSecret( secret )
key_from_secret( secret )
KeyFromSecret( secret )
Description
The KeyFromSecret
function retrieves a key document given a key’s
secret string, or a token document given a token’s secret string.
Parameter
Argument | Type | Definition and Requirements |
---|---|---|
|
The secret identifying an existing key or token. |
Returns
An object containing data returned by performing a lookup for the secret. If the secret does not match an existing key or token, an error is returned.
When the secret string identifies a key, the object has the following fields:
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
The reference identifies the key that was retrieved. |
|
|
The timestamp, with microsecond resolution, reporting the most recent modification time of the key. |
|
|
A reference to the database the key is protecting. |
|
|
The security role for this key. |
|
|
The hash of the secret. |
When the secret string identifies a token, the object has the following fields:
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
The reference identifies the token instance that was retrieved. |
|
|
The timestamp, with microsecond resolution, reporting the most recent modification of the token. |
|
|
A reference to the document representing the logged-in user (the one
passed to the |
|
|
A hash of the secret. The secret is not recoverable from this value. |
Examples
The following query retrieves a key by providing a given secret:
client.Query(
KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"));
{
"ref": { "@ref": "keys/181388638431478272" },
"class": { "@ref": "keys" },
"ts": 1509244535744675,
"database": { "@ref": "databases/prydain" },
"role": "server",
"hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}
curl https://db.fauna.com/ \
-u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
-d '{ "key_from_secret": "fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL" }'
HTTP/1.1 200 OK
{
"resource": {
"ref": { "@ref": "keys/181388638431478272" },
"class": { "@ref": "keys" },
"ts": 1509244535744675,
"database": { "@ref": "databases/prydain" },
"role": "server",
"hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}
}
result, _ := client.Query(
f.KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"),
)
fmt.Println(result)
map[ref:{181388638431478272 0xc42023fc00 <nil>} ts:1509244535744675 database:{prydain 0xc42023fda0 <nil>} role:server hashed_secret:$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu]
System.out.println(
client.query(
KeyFromSecret(
Value("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL")
)
).get());
{
ref: ref(id = "200886770939724288", collection = ref(id = "keys")),
ts: 1527839403941254,
database: ref(id = "prydain", collection = ref(id = "databases")),
role: "server",
hashed_secret: "$2a$05$Gi4GT2NU2LGjb7LuoNAvue/eScTIkaEk1xeBLDOZSCiX2seM/zgDS"
}
client.query(
q.KeyFromSecret('fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL')
)
.then((ret) => console.log(ret))
{ ref: Ref(id=181388638431478272, collection=Ref(id=keys)),
ts: 1509244535744675,
database: Ref(id=prydain, collection=Ref(id=databases)),
role: "server",
hashed_secret: "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu" }
client.query(
q.key_from_secret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"))
{
"ref": { "@ref": "keys/181388638431478272" },
"class": { "@ref": "keys" },
"ts": 1509244535744675,
"database": { "@ref": "databases/prydain" },
"role": "server",
"hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}
client.query(
KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"))
{
"ref": { "@ref": "keys/181388638431478272" },
"class": { "@ref": "keys" },
"ts": 1509244535744675,
"database": { "@ref": "databases/prydain" },
"role": "server",
"hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}
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!