SDK
SDK Jvm v1.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.

:::: tabs ::: tab Java

Arguments #

Copied to clipboard!
CompletableFuture<Map<String, Object>> login(
  final String strategy,
  final Map<String, Object> credentials,
  final String expiresIn) 
  throws NotConnectedException, InternalException

CompletableFuture<Map<String, Object>> login(
  final String strategy,
  final Map<String, Object> credentials) 
  throws NotConnectedException, InternalException

Argument Type Description
strategy
String
Strategy to use
credentials
Map<String, Object>
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:

Property Type Description
_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 #

Copied to clipboard!
Map<String, Object> credentials = new HashMap<>();
  credentials.put("username", "foo");
  credentials.put("password", "bar");
Map<String, Object> result =
  kuzzle.getAuthController().login("local", credentials).get();

::: ::: tab Kotlin

Arguments #

Copied to clipboard!
fun login(
  strategy: String,
  credentials: Map<String, Any?>?,
  expiresIn: String? = null): CompletableFuture<Map<String, Any?>>

Argument Type Description
strategy
String
Strategy to use
credentials
Map<String, Any?>
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:

Property Type Description
_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 #

Copied to clipboard!
val result: Map<String, Any?> =
  kuzzle.authController.login("local", HashMap<String, Any?>().apply {
    put("username", "foo")
    put("password", "bar")
  }).get()

::: ::::