Authenticate user and issue tokens
1 min
code examples curl request post \\ \ url http //localhost 10101/api/v1/auth/login \\ \ header 'accept application/json' \\ \ header 'content type application/json' \\ \ data raw '{ "username" "user\@example com", "password" "securepassword123", "tokentype" "consumer" }'var myheaders = new headers(); myheaders append("accept", "application/json"); myheaders append("content type", "application/json"); var raw = json stringify({ "username" "user\@example com", "password" "securepassword123", "tokentype" "consumer" }); var requestoptions = { method 'post', headers myheaders, body raw, redirect 'follow' }; fetch("http //localhost 10101/api/v1/auth/login", requestoptions) then(response => response text()) then(result => console log(result)) catch(error => console log('error', error));require "uri" require "json" require "net/http" url = uri("http //localhost 10101/api/v1/auth/login") http = net http new(url host, url port); request = net http post new(url) request\["accept"] = "application/json" request\["content type"] = "application/json" request body = json dump({ "username" "user\@example com", "password" "securepassword123", "tokentype" "consumer" }) response = http request(request) puts response read body import requests import json url = "http //localhost 10101/api/v1/auth/login" payload = json dumps({ "username" "user\@example com", "password" "securepassword123", "tokentype" "consumer" }) headers = { 'accept' 'application/json', 'content type' 'application/json' } response = requests request("post", url, headers=headers, data=payload) print(response text) responses // authentication result either successful authentication with tokens (mfarequired=false or absent) mfa challenge required (mfarequired=true) { "mfarequired" false, "accesstoken" "eyjhbgcioijsuzi1niisinr5cci6ikpxvcj9 ", "refreshtoken" "eyjhbgcioijsuzi1niisinr5cci6ikpxvcj9 ", "expiresin" 3600, "tokentype" "bearer", "mfachallengeid" "ch abc123xyz", "mfamethod" "totp", "mfaexpiresin" 300, "mfamaskedphonenumber" " 1234" }// bad request invalid json, missing fields, or tenant selection required { "error" "unauthorized", "message" "invalid username or password", "code" "unauthorized" }// invalid credentials { "error" "unauthorized", "message" "invalid username or password", "code" "unauthorized" }// forbidden unauthorized tenant or no authorized tenants { "error" "unauthorized", "message" "invalid username or password", "code" "unauthorized" }// internal server error { "error" "unauthorized", "message" "invalid username or password", "code" "unauthorized" }