Login
Login( identity, param_object )
Login( identity, param_object )
Login( identity, param_object )
Login( identity, param_object )
login( identity, param_object )
Login( identity, param_object )
Description
The Login
function creates an authentication token for the provided
identity
, which can be a Ref or a
Set of refs, based on the password provided in
param_object
.
The authentication token’s secret can be used to connect to Fauna and
execute queries within the database that contains identity
. The
permissions granted to the authentication token can be specified using
Attribute-based access control (ABAC).
If the identity
is not a member of at least one ABAC role, it has no
privileges to read or write documents.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
The identity (reference to a document) or identities (set of refs to multiple documents) to authenticate. |
|
|
The |
param_object
Field Name | Field Type | Definition and Requirements | ||
---|---|---|---|---|
|
Optional - a document storing metadata about the token to be created. |
|||
|
The password to authenticate |
|||
|
Optional - A timestamp indicating the authentication token’s time-to-live, which is when the token should be removed. When a token is removed, the token’s existence ceases (temporal queries cannot recover the token) and the associated secret can no longer be used to authenticate.
|
Returns
When authentication is successful, an object containing the authenticated Ref(s) is returned. When authentication fails, an error is returned.
Examples
client.Query(
Login(
Ref(Collection("characters"), "181388642114077184"),
Obj("password", "abracadabra")
)
);
ObjectV(ref: RefV(id = "280491620815602176", collection = RefV(id = "tokens")),ts: LongV(1603756504750000),instance: RefV(id = "181388642114077184", collection = RefV(id = "characters", collection = RefV(id = "collections"))),secret: StringV(fnED5IGknTACAAPkgaNqIAIAx6peH_1tJ7X82fJ7bcOF6exEWYw))
result, err := client.Query(
f.Login(
f.Ref(f.Collection("characters"), "181388642114077184"),
f.Obj{"password": "abracadabra"}))
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Println(result)
}
map[instance:{181388642114077184 0xc00008e3f0 0xc00008e3f0 <nil>} ref:{280481898848846336 0xc00008e240 0xc00008e240 <nil>} secret:fnED5HjNCtACAAPkeMygwAIA1rfQDqKRQAnHrDBoN1a_DgsbVMw ts:1603747233160000]
System.out.println(
client.query(
Login(
Ref(Collection("characters"), Value(181388642114077184L)),
Obj("password", Value("abracadabra"))
)
).get());
{ref: ref(id = "269701642908074496", collection = ref(id = "tokens")), ts: 1593466379950000, instance: ref(id = "181388642114077184", collection = ref(id = "characters", collection = ref(id = "collections"))), secret: "fnEDviw3HOACAAO-LDL9UAIAe6cFd6PJDjOcXLSnrSH2s6K97Fk"}
client.query(
q.Login(
q.Ref(q.Collection('characters'), '181388642114077184'),
{ password: 'abracadabra' },
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
ref: Ref(Tokens(), "268283157930836480"),
ts: 1592113607250000,
instance: Ref(Collection("characters"), "181388642114077184"),
secret: 'fnEDuSIcV7ACAAO5IhwXkAIAMQbrsrZaHs1cUWnligxyD5kUAPE'
}
result = client.query(
q.login(
q.ref(q.collection("characters"), "181388642114077184"),
{"password": "abracadabra"}
)
)
print(result)
{'ref': Ref(id=269168498780930560, collection=Ref(id=tokens)), 'ts': 1592957934080000, 'instance': Ref(id=181388642114077184, collection=Ref(id=characters, collection=Ref(id=collections))), 'secret': 'fnEDvEdS0pACAAO8R1KZUAIAswCZXMn3gnH_93FC7t_-eRUlqCU'}
client.query(
Login(
Ref(Collection("characters"), "181388642114077184"),
Obj("password" -> "abracadabra")))
{ref: ref(id = "270774096773513728", collection = ref(id = "tokens")), ts: 1594489151640000, instance: ref(id = "181388642114077184", collection = ref(id = "characters", collection = ref(id = "collections"))), secret: "fnEDwfubPJACAAPB-5Ru4AIAgnYlhCKrBBQ9EGB1Vs8VyL8H78U"}
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!