Class DefaultRefreshTokenProvider

java.lang.Object
org.keycloak.protocol.oidc.refresh.AbstractRefreshTokenProvider
org.keycloak.protocol.oidc.refresh.DefaultRefreshTokenProvider
All Implemented Interfaces:
RefreshTokenProvider, org.keycloak.provider.Provider

public class DefaultRefreshTokenProvider extends AbstractRefreshTokenProvider implements RefreshTokenProvider
Default refresh token provider. Requires valid user session, which is referenced in the refresh token, to be present in Keycloak storage
  • Constructor Details

    • DefaultRefreshTokenProvider

      public DefaultRefreshTokenProvider(org.keycloak.models.KeycloakSession session)
  • Method Details

    • supports

      public boolean supports(InitialRefreshTokenContext initialRefreshTokenCtx)
      Description copied from interface: RefreshTokenProvider
      Method is triggered during initial issuance of refresh token - usually after successful user authentication.
      Specified by:
      supports in interface RefreshTokenProvider
      Parameters:
      initialRefreshTokenCtx - context information with the data useful to determine if this provider can be used to generate refresh token
      Returns:
      true if this provider can be used to generate refresh token. In this case method RefreshTokenProvider.generateRefreshToken(InitialRefreshTokenContext) would be used for this provider to generate new refresh token. Keycloak iterates over available providers to determine which one can be used. Providers are sorted by their priority (based on the "order" of particular ProviderFactory)
    • generateRefreshToken

      public org.keycloak.representations.RefreshToken generateRefreshToken(InitialRefreshTokenContext initialRefreshTokenCtx)
      Description copied from interface: RefreshTokenProvider
      Method is triggered during initial issuance of refresh token - usually after successful user authentication. Refresh token is generated by single provider, which was first available provider returned by method RefreshTokenProvider.supports(InitialRefreshTokenContext)
      Specified by:
      generateRefreshToken in interface RefreshTokenProvider
      Parameters:
      initialRefreshTokenCtx - context information with the data useful to determine
      Returns:
      newly generated refresh token
    • supports

      public boolean supports(RefreshTokenContext ctx)
      Description copied from interface: RefreshTokenProvider
      Invoked during refresh-token request.
      Specified by:
      supports in interface RefreshTokenProvider
      Parameters:
      ctx - Context, which contains old refresh token and some other data
      Returns:
      True if this provider supports verification of the refresh token from the context
    • validateToken

      protected TokenManager.TokenValidation validateToken(org.keycloak.models.KeycloakSession session, jakarta.ws.rs.core.UriInfo uriInfo, org.keycloak.common.ClientConnection connection, org.keycloak.models.RealmModel realm, org.keycloak.representations.RefreshToken oldToken, jakarta.ws.rs.core.HttpHeaders headers, String scope, org.keycloak.models.ClientModel client, TokenManager tokenManager, org.keycloak.events.EventBuilder event) throws org.keycloak.OAuthErrorException
      Description copied from class: AbstractRefreshTokenProvider
      Validation specific to the particular refreshToken provider type. For example this could be validation if related user session still exists and is not expired etc.
      Specified by:
      validateToken in class AbstractRefreshTokenProvider
      Returns:
      token validation with successful context information
      Throws:
      org.keycloak.OAuthErrorException - In case that some validation failed
    • afterRefreshTokenGenerated

      protected void afterRefreshTokenGenerated(RefreshTokenContext ctx, TokenManager.AccessTokenResponseBuilder responseBuilder)
      Description copied from class: AbstractRefreshTokenProvider
      Callback method invoked after refresh token is generated
      Specified by:
      afterRefreshTokenGenerated in class AbstractRefreshTokenProvider
      Parameters:
      ctx - context
      responseBuilder - response builder with already filled refresh token and client session context