Class OAuth20Service

    • Field Detail

      • responseType

        private final java.lang.String responseType
      • defaultScope

        private final java.lang.String defaultScope
    • Constructor Detail

      • OAuth20Service

        public OAuth20Service​(DefaultApi20 api,
                              java.lang.String apiKey,
                              java.lang.String apiSecret,
                              java.lang.String callback,
                              java.lang.String defaultScope,
                              java.lang.String responseType,
                              java.io.OutputStream debugStream,
                              java.lang.String userAgent,
                              HttpClientConfig httpClientConfig,
                              HttpClient httpClient)
    • Method Detail

      • getVersion

        public java.lang.String getVersion()
        Returns the OAuth version of the service.
        Specified by:
        getVersion in class OAuthService
        Returns:
        OAuth version as string
      • signRequest

        public void signRequest​(java.lang.String accessToken,
                                OAuthRequest request)
      • getAuthorizationUrl

        public java.lang.String getAuthorizationUrl()
        Returns the URL where you should redirect your users to authenticate your application.
        Returns:
        the URL where you should redirect your users
      • getAuthorizationUrl

        public java.lang.String getAuthorizationUrl​(java.lang.String state)
      • getAuthorizationUrl

        public java.lang.String getAuthorizationUrl​(java.util.Map<java.lang.String,​java.lang.String> additionalParams)
        Returns the URL where you should redirect your users to authenticate your application.
        Parameters:
        additionalParams - any additional GET params to add to the URL
        Returns:
        the URL where you should redirect your users
      • getAuthorizationUrl

        public java.lang.String getAuthorizationUrl​(PKCE pkce)
      • extractAuthorization

        public OAuth2Authorization extractAuthorization​(java.lang.String redirectLocation)
      • getResponseType

        public java.lang.String getResponseType()
      • getDefaultScope

        public java.lang.String getDefaultScope()
      • logRequestWithParams

        protected void logRequestWithParams​(java.lang.String requestDescription,
                                            OAuthRequest request)
      • sendAccessTokenRequestSync

        protected OAuth2AccessToken sendAccessTokenRequestSync​(OAuthRequest request)
                                                        throws java.io.IOException,
                                                               java.lang.InterruptedException,
                                                               java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessTokenAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenAsync​(java.lang.String code)
      • getAccessToken

        public OAuth2AccessToken getAccessToken​(java.lang.String code)
                                         throws java.io.IOException,
                                                java.lang.InterruptedException,
                                                java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessToken

        public OAuth2AccessToken getAccessToken​(AccessTokenRequestParams params)
                                         throws java.io.IOException,
                                                java.lang.InterruptedException,
                                                java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • createRefreshTokenRequest

        protected OAuthRequest createRefreshTokenRequest​(java.lang.String refreshToken,
                                                         java.lang.String scope)
      • refreshAccessTokenAsync

        public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync​(java.lang.String refreshToken)
      • refreshAccessTokenAsync

        public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync​(java.lang.String refreshToken,
                                                                                      java.lang.String scope)
      • refreshAccessToken

        public OAuth2AccessToken refreshAccessToken​(java.lang.String refreshToken)
                                             throws java.io.IOException,
                                                    java.lang.InterruptedException,
                                                    java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • refreshAccessToken

        public OAuth2AccessToken refreshAccessToken​(java.lang.String refreshToken,
                                                    java.lang.String scope)
                                             throws java.io.IOException,
                                                    java.lang.InterruptedException,
                                                    java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • createAccessTokenPasswordGrantRequest

        protected OAuthRequest createAccessTokenPasswordGrantRequest​(java.lang.String username,
                                                                     java.lang.String password,
                                                                     java.lang.String scope)
      • getAccessTokenPasswordGrant

        public OAuth2AccessToken getAccessTokenPasswordGrant​(java.lang.String username,
                                                             java.lang.String password)
                                                      throws java.io.IOException,
                                                             java.lang.InterruptedException,
                                                             java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessTokenPasswordGrant

        public OAuth2AccessToken getAccessTokenPasswordGrant​(java.lang.String username,
                                                             java.lang.String password,
                                                             java.lang.String scope)
                                                      throws java.io.IOException,
                                                             java.lang.InterruptedException,
                                                             java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessTokenPasswordGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username,
                                                                                               java.lang.String password)
      • getAccessTokenPasswordGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username,
                                                                                               java.lang.String password,
                                                                                               java.lang.String scope)
      • getAccessTokenPasswordGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username,
                                                                                               java.lang.String password,
                                                                                               OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
        Request Access Token Password Grant async version
        Parameters:
        username - User name
        password - User password
        callback - Optional callback
        Returns:
        Future
      • createAccessTokenClientCredentialsGrantRequest

        protected OAuthRequest createAccessTokenClientCredentialsGrantRequest​(java.lang.String scope)
      • getAccessTokenClientCredentialsGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrantAsync()
      • getAccessTokenClientCredentialsGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrantAsync​(java.lang.String scope)
      • getAccessTokenClientCredentialsGrant

        public OAuth2AccessToken getAccessTokenClientCredentialsGrant()
                                                               throws java.io.IOException,
                                                                      java.lang.InterruptedException,
                                                                      java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessTokenClientCredentialsGrant

        public OAuth2AccessToken getAccessTokenClientCredentialsGrant​(java.lang.String scope)
                                                               throws java.io.IOException,
                                                                      java.lang.InterruptedException,
                                                                      java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • getAccessTokenClientCredentialsGrant

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrant​(OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
        Start the request to retrieve the access token using client-credentials grant. The optionally provided callback will be called with the Token when it is available.
        Parameters:
        callback - optional callback
        Returns:
        Future
      • createRevokeTokenRequest

        protected OAuthRequest createRevokeTokenRequest​(java.lang.String tokenToRevoke,
                                                        TokenTypeHint tokenTypeHint)
      • revokeTokenAsync

        public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync​(java.lang.String tokenToRevoke)
      • revokeTokenAsync

        public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync​(java.lang.String tokenToRevoke,
                                                                            TokenTypeHint tokenTypeHint)
      • revokeToken

        public void revokeToken​(java.lang.String tokenToRevoke)
                         throws java.io.IOException,
                                java.lang.InterruptedException,
                                java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • revokeToken

        public void revokeToken​(java.lang.String tokenToRevoke,
                                TokenTypeHint tokenTypeHint)
                         throws java.io.IOException,
                                java.lang.InterruptedException,
                                java.util.concurrent.ExecutionException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • revokeToken

        public java.util.concurrent.Future<java.lang.Void> revokeToken​(java.lang.String tokenToRevoke,
                                                                       OAuthAsyncRequestCallback<java.lang.Void> callback)
      • revokeToken

        public java.util.concurrent.Future<java.lang.Void> revokeToken​(java.lang.String tokenToRevoke,
                                                                       OAuthAsyncRequestCallback<java.lang.Void> callback,
                                                                       TokenTypeHint tokenTypeHint)
      • checkForErrorRevokeToken

        private void checkForErrorRevokeToken​(Response response)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • createDeviceAuthorizationCodesRequest

        protected OAuthRequest createDeviceAuthorizationCodesRequest​(java.lang.String scope)
      • getDeviceAuthorizationCodes

        public DeviceAuthorization getDeviceAuthorizationCodes()
                                                        throws java.lang.InterruptedException,
                                                               java.util.concurrent.ExecutionException,
                                                               java.io.IOException
        Requests a set of verification codes from the authorization server with the default scope
        Returns:
        DeviceAuthorization
        Throws:
        java.lang.InterruptedException - InterruptedException
        java.util.concurrent.ExecutionException - ExecutionException
        java.io.IOException - IOException
        See Also:
        RFC 8628
      • getDeviceAuthorizationCodes

        public DeviceAuthorization getDeviceAuthorizationCodes​(java.lang.String scope)
                                                        throws java.lang.InterruptedException,
                                                               java.util.concurrent.ExecutionException,
                                                               java.io.IOException
        Requests a set of verification codes from the authorization server
        Parameters:
        scope - scope
        Returns:
        DeviceAuthorization
        Throws:
        java.lang.InterruptedException - InterruptedException
        java.util.concurrent.ExecutionException - ExecutionException
        java.io.IOException - IOException
        See Also:
        RFC 8628
      • getDeviceAuthorizationCodesAsync

        public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodesAsync()
      • getDeviceAuthorizationCodesAsync

        public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodesAsync​(java.lang.String scope)
      • createAccessTokenDeviceAuthorizationGrantRequest

        protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest​(DeviceAuthorization deviceAuthorization)
      • getAccessTokenDeviceAuthorizationGrantAsync

        public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenDeviceAuthorizationGrantAsync​(DeviceAuthorization deviceAuthorization)
      • pollAccessTokenDeviceAuthorizationGrant

        public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant​(DeviceAuthorization deviceAuthorization)
                                                                  throws java.lang.InterruptedException,
                                                                         java.util.concurrent.ExecutionException,
                                                                         java.io.IOException
        Periodically tries to get a token from a server (waiting for the user to give consent). Sync only version. No Async variants yet, one should implement async scenarios themselves.
        Parameters:
        deviceAuthorization - deviceAuthorization
        Returns:
        token
        Throws:
        java.lang.InterruptedException - InterruptedException
        java.util.concurrent.ExecutionException - ExecutionException
        java.io.IOException - IOException
        OAuth2AccessTokenErrorResponse - Indicates OAuth error.
        See Also:
        getDeviceAuthorizationCodes()