Skip to main content

Extend Keycloak Token Validity

๐ŸŽฏcontext

Keycloack tokens are used to authenticate the services that are being developed. They have a default timeout validity and hence during development you might get several errors resulting from an expired token. To avoid these errors, you can extend the authentication token validity in your Keycloack settings. This How-To will cover the necessary steps to extend your Keycloak token validity.

Descriptionโ€‹

During development, an expired token can be a hindrance to smoothly complete your project. You want to extend Keycloak token validity rather than the default timeout validity.

๐Ÿ’กtip

To do this, you need to have administrative rights in the realm that is used to authenticate services being developed or contact your administrator to follow the steps.

Stepsโ€‹

  1. Open your Keycloak account and click on Administration Console.

    Keycloak Home
  2. Select your Realm, you will then see it at the top left side bar.

    Select a Realm

Case 1 : Increase the token validity for a specific clientโ€‹

  1. From the left side bar, click on "Clients" to view all the configured clients.

  2. Identify the client you want to increase the token validity for and click on Edit.

  1. Scroll down to "Advanced Settings" section.

  2. Change the input in "Access Token Lifespan" and click Save.

Case 2 : Increase the token validity across the Realmโ€‹

  1. From the left side bar, click on "Realm Settings".

  2. Navigate to "Tokens" tab.

  3. Scroll down to "Access Token Lifespan" field.

  4. Change the input and click Save.

โ„น๏ธnote

Increasing token validity timelines negatively impacts security and should never be done in a production environment.

๐ŸŒŸWell Done

You have successfully extended the validity of your access token.