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

Arguments

Copied to clipboard!
func (a *Auth) Login(
  strategy string,
  credentials json.RawMessage,
  expiresIn *int) (string, error)
Arguments Type Description Required
strategy
string
Name of the strategy to use yes
credentials
string
Credentials for that strategy yes
expiresIn
int
Expiration time, in milliseconds no

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 in 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

The login action returns an encrypted JSON Web Token, that must then be sent in the requests headers.

Usage

Copied to clipboard!
_, err := kuzzle.Auth.Login("local", json.RawMessage("{\"username\":\"foo\",\"password\":\"bar\"}"), nil)

if err != nil {
  log.Fatal(err)
} else {
  fmt.Printf("Success")
}