Skip to main content

Password

This section describes how to procure an access token for authorization using the password as a grant type.

Access token requirements: Username, Password along with ClientID is required to get the Access Token.

Request

Request headers

KeyValueDescription
Content-Typeapplication/x-www-form-urlencodedMethod for sending name-value pairs data to the server, such as the information you typed into a HTML form.

HTTP request

POST https://{tenantId}.{hostname}/auth/realms/{tenantId}/protocol/openid-connect/token
note

API requests must be made over https. Calls made over plain http will fail.

Request body (*Required)

Parameter NameTypeDescription
grant_type*StringThe grant type should be password.
username*StringThe username for which the token needs to be generated.
password*StringPassword corresponding to the username.
client_id*StringThe Client ID for which the access token is to be generated.
client_secretStringSecret corresponding to the given clientID. Secret will be available only for the clients with access type selected confidential during client creation. This is an optional parameter.
curl --location --request POST 'https://{tenantId}.{hostname}/auth/realms/{tenantId}/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=testuser' \
--data-urlencode 'password=abc123' \
--data-urlencode 'client_id=demo' \
--data-urlencode 'client_secret=4d759a23-e01d-4902-8727-98'

Response

Parameter NameTypeDescription
access_tokenStringThe newly created access token.
expires_inIntegerValidity of the access token in seconds.
refresh_expires_inIntegerValidity of the refresh token in seconds.
refresh_tokenStringThe new refresh token.
token_typeStringIndicates access token type.
not-before-policyIntegernot-before policy ensures that any tokens issued before that time become invalid.
session_stateIntegerThe Client ID salted cryptographic hash, the root URL, and the browser state are all included in the session state value. Basically session_state value is used to monitor end user sessions.
scopeStringThe scope requested for the token.

Sample Response

{
"access_token": String,
"expires_in": Integer,
"refresh_expires_in": Integer,
"refresh_token": String,
"token_type": "Bearer",
"not-before-policy": 0,
"session_state": String,
"scope": String
}

Response Status Information

Status CodeStatusMessage
200OKOK
400Bad RequestUnsupported grant_type
400Bad RequestInvalid client credentials
401UnauthorizedInvalid user credentials
401UnauthorizedInvalid client secret
404Not FoundRealm does not exist