How to Dev - Example: Get access token via refresh token

×

Warning message

  • You can't delete this newsletter because it has not been sent to all its subscribers.
  • You can't delete this newsletter because it has not been sent to all its subscribers.

 

To get access token using the refresh token acquired during authentication the following REST API is available:

POST https://www.snap4city.org/auth/realms/master/protocol/openid-connect/token

Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&client_id=xxx&refresh_token=…refresh token…

 

Return 200 if the refresh token is valid, access token is returned

{

    "access_token": "…",

    "expires_in": 1500,

    "refresh_expires_in": 2073600,

    "refresh_token": "…",

    "token_type": "bearer",

    "not-before-policy": 0,

    "session_state": "…"

}

 

Return 400 if the refresh token is not valid or the client_id is not present

{

    "error": "invalid_grant",

    "error_description": "Invalid refresh token"

}

Note: each authentication request creates a new session on keycloak, it is better to use the refresh token to create a new access token, it is more secure (no need to store user name and password)

 

 

 

How to Dev - Example: Get access token via refresh token | Snap4City

Error

×

Error message

  • Notice: Trying to get property of non-object in user_is_logged_in() (line 1576 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_is_logged_in() (line 1576 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in og_field_access() (line 578 of /var/www/html/drupal/sites/default/modules/og/og.module).
  • Notice: Trying to get property of non-object in user_access() (line 806 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 818 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 819 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 825 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 828 of /var/www/html/drupal/modules/user/user.module).
  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/drupal/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/drupal/includes/bootstrap.inc).
  • Error: __clone method called on non-object in og_user_access_entity() (line 2249 of /var/www/html/drupal/sites/default/modules/og/og.module).
The website encountered an unexpected error. Please try again later.