Skip to main content

Refresh Token

A refresh token is a credential artefact that allows a client application to obtain new access tokens without requiring the user to log in back. Client apps can utilize a refresh token to "refresh" access tokens once they have expired. Access tokens will only be valid for a short time for security reasons. When you get an access token, you'll get a refresh token in the response.

Resource Informations

NameValueDescription
Requires authentication?YesClientID is required for this authentication
Rate limited?NoRate limited indicate how many requests a client can make in a time period

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.

Request URL

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)

Field NameTypeDescription
grant_type*StringGrant Type should set to refresh_token.
refresh_token*StringThe refresh token to be used. Use any one of the methods listed under Create Access Token to get the refresh token.
client_id*StringThe refresh token will be generated for the given client.
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.

Sample Request

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=refresh_token' \
--data-urlencode 'refresh_token=eyJhbGc' \
--data-urlencode 'client_id=test'

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": "UIiwia2lkIiA6ICJiZTIxM",
"expires_in": 18000,
"refresh_expires_in": 1800,
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR",
"token_type": "Bearer",
"not-before-policy": 0,
"session_state": "asdasdwx-81ed-4942-ab59-6c8799171abb",
"scope": "scope"
}

Response Status Information

Status CodeStatusMessage
200OKOK
400Bad RequestInvalid refresh token
401UnauthorizedHTTP 401 Unauthorized
401UnauthorizedInvalid client secret
404Not FoundRealm does not exist