Class RefreshableTokenSource

  • All Implemented Interfaces:
    TokenSource
    Direct Known Subclasses:
    ClientCredentials, CliTokenSource, SessionCredentials

    public abstract class RefreshableTokenSource
    extends Object
    implements TokenSource
    An OAuth TokenSource which can be refreshed.

    Calls to getToken() will first check if the token is still valid (currently defined by having at least 10 seconds until expiry). If not, refresh() is called first to refresh the token.

    • Field Detail

      • token

        protected Token token
    • Constructor Detail

      • RefreshableTokenSource

        public RefreshableTokenSource()
      • RefreshableTokenSource

        public RefreshableTokenSource​(Token token)
    • Method Detail

      • retrieveToken

        protected static Token retrieveToken​(HttpClient hc,
                                             String clientId,
                                             String clientSecret,
                                             String tokenUrl,
                                             Map<String,​String> params,
                                             Map<String,​String> headers,
                                             AuthParameterPosition position)
        Helper method implementing OAuth token refresh.
        Parameters:
        clientId - The client ID to authenticate with.
        clientSecret - The client secret to authenticate with.
        tokenUrl - The authorization URL for fetching tokens.
        params - Additional request parameters.
        headers - Additional headers.
        position - The position of the authentication parameters in the request.
        Returns:
        The newly fetched Token.
      • refresh

        protected abstract Token refresh()