SDK
SDK Java 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

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

Argument Type Description
strategy
String
Strategy to use
credentials
ConcurrentHashMap<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!
ConcurrentHashMap<String, Object> credentials = new ConcurrentHashMap<>();
  credentials.put("username", "foo");
  credentials.put("password", "bar");
ConcurrentHashMap<String, Object> result = 
  kuzzle.getAuthController().login("local", credentials).get();