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 jwt property is manually unset.


Copied to clipboard!
std::string login(const std::string& strategy, const std::string& credentials);

std::string login(
    const std::string& strategy,
    const std::string& credentials,
    int expiresIn);

Arguments Type Description
const std::string&
Strategy to use
const std::string&
JSON string representing the credentials
Expiration time, in milliseconds


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.


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


Returns the encrypted JSON Web Token. Once auth:login has been called, the returned JWT is stored by the SDK and used for all the subsequent API call, ensuring they are properly authenticated.


Throws a kuzzleio::KuzzleException if there is an error. See how to handle error.


Copied to clipboard!
try {
  std::string jwt = kuzzle->auth->login("local", R"({"username":"foo","password":"bar"})");

  std::cout << "Success" << std::endl;
} catch (kuzzleio::KuzzleException &e) {
  std::cerr << e.what() << std::endl;