JSON API » user » user/login

Gets the login data for the authentication user, based on the person logging in as.

If the user has TOTP (two-factor authentication) enabled, the login is a two-step process. First call without auth_code to receive a 202 response containing a temporary token. Then call again with that token and the TOTP code to complete login.

Input parameters

Requires authentication and the user role privilege.

NameTypeDescriptionRequiredDefault value
auth_usernameStringAuthentication username. Required for step 1.Yes (step 1)
auth_passwordStringAuthentication password. Required for step 1.Yes (step 1)
auth_codeStringTOTP code from authenticator app. Supply in step 1 for one-step login, or in step 2 for two-step login.No
totp_tokenStringTemporary token received in the 202 response. Triggers step 2 TOTP validation when supplied.No
tokenInteger1 to get an authentication token, 0 not to.No0

Responses

CodeDescription
200Success.
202Password correct but TOTP code required. Returns totp_token, username, and totp_required in data. Use the token in a second call with auth_code to complete login.
401The authentication details provided are invalid, or the TOTP token is invalid or expired.
402Your role does not allow this.

Data returned (200)

Fields of user.

Data returned (202)

FieldTypeDescription
totp_requiredBooleanAlways true.
totp_tokenStringTemporary JWT to use in the second login call. Valid for 2 minutes.
usernameStringThe username that was authenticated.

Example: Login without TOTP

http://enswitch.example.com/api/json/user/login/?auth_username=user;auth_password=password

{ "responses":[ { "code":"200", "key":"", "message":"OK" } ], "data":{ "id":123, "username":"user", ... } }

Example: Step 1 - Password only (TOTP required)

http://enswitch.example.com/api/json/user/login/?auth_username=user;auth_password=password

{ "responses":[ { "code":"202", "key":"", "message":"OK" } ], "data":{ "totp_required":true, "totp_token":"eyJ...", "username":"user" } }

Example: Step 2 - TOTP code with temporary token

http://enswitch.example.com/api/json/user/login/?totp_token=eyJ...;auth_code=123456

{ "responses":[ { "code":"200", "key":"", "message":"OK" } ], "data":{ "id":123, "username":"user", ... } }

Example: One-step login (password and TOTP code together)

http://enswitch.example.com/api/json/user/login/?auth_username=user;auth_password=password;auth_code=123456

{ "responses":[ { "code":"200", "key":"", "message":"OK" } ], "data":{ "id":123, "username":"user", ... } }

Change history

VersionChanges
4.4TOTP two-step login support added: auth_code, totp_token parameters added; 202 response added.
4.1token input parameter added.
3.13Function added.