SDK
SDK Dart Null Safety v3.x
2

Login #

Authenticates a user.

If this action is successful, all further requests emitted by this SDK instance will be in the name of the authenticated user, until either the authenticated token expires, the logout action is called, or the authentication token property is manually unset.

Arguments #

Future<String> login(String strategy, Map<String, dynamic> credentials,
          {String? expiresIn})

ArgumentTypeDescription
strategy
String
Strategy to use
credentials
Map<String, dynamic>
Hashmap representing the credentials
expiresIn
String?
Token duration

strategy #

The name of the authentication strategy used to log the user in.

Depending on the chosen authentication strategy, additional credential arguments may be required. The API request example on this page provides the necessary arguments for the local authentication plugin.

Check the appropriate authentication plugin documentation to get the list of additional arguments to provide.

expiresIn #

The default value for the expiresIn option is defined at server level, in Kuzzle's configuration file.

Return #

Returns a Hashmap with the following properties:

PropertyTypeDescription
_id
String
User's kuid
jwt
String
Encrypted authentication token, that must then be sent in the requests headers or in the query
expiresAt
int
Token expiration date, in Epoch-millis (UTC)
ttl
int
Token time to live, in milliseconds

Once auth:login has been called, the returned authentication token is stored by the SDK and used for all the subsequent API call, ensuring they are properly authenticated.

Usage #

final result = await kuzzle
  .auth
  .login(
    'local',
    {
      'username': 'foo',
      'password': 'bar'
    }
  );