Class AbstractOAuthService

  • All Implemented Interfaces:
    IOAuthService
    Direct Known Subclasses:
    LinkedIn

    public abstract class AbstractOAuthService
    extends java.lang.Object
    implements IOAuthService
    The abstract service service using OAuth1/OAuth2.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected AccessToken accessToken
      The access token, null for none.
      protected com.github.scribejava.core.oauth.OAuth10aService service1
      The OAuth 1.0a authentication service.
      protected com.github.scribejava.core.oauth.OAuth20Service service2
      The OAuth 2.0 authentication service.
      protected OAuthSession session
      The session.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractOAuthService​(OAuthSession session, com.github.scribejava.core.oauth.OAuth10aService service)
      Constructs the service for OAuth 1.0a.
      AbstractOAuthService​(OAuthSession session, com.github.scribejava.core.oauth.OAuth20Service service)
      Constructs the service for OAuth 2.0.
    • Field Detail

      • session

        protected final OAuthSession session
        The session.
      • service1

        protected final com.github.scribejava.core.oauth.OAuth10aService service1
        The OAuth 1.0a authentication service.
      • service2

        protected final com.github.scribejava.core.oauth.OAuth20Service service2
        The OAuth 2.0 authentication service.
      • accessToken

        protected AccessToken accessToken
        The access token, null for none.
    • Constructor Detail

      • AbstractOAuthService

        public AbstractOAuthService​(OAuthSession session,
                                    com.github.scribejava.core.oauth.OAuth20Service service)
        Constructs the service for OAuth 2.0.
        Parameters:
        session - The session.
        service - The service.
        Throws:
        java.lang.NullPointerException - If session or service is null.
      • AbstractOAuthService

        public AbstractOAuthService​(OAuthSession session,
                                    com.github.scribejava.core.oauth.OAuth10aService service)
        Constructs the service for OAuth 1.0a.
        Parameters:
        session - The session.
        service - The service.
        Throws:
        java.lang.NullPointerException - If session or service is null.
    • Method Detail

      • createServiceBuilder

        protected static com.github.scribejava.core.builder.ServiceBuilder createServiceBuilder​(java.lang.String clientID,
                                                                                                java.lang.String clientSecret)
        Creates a ServiceBuilder that is initialized for debugging or not.
        Parameters:
        clientID - The Client ID.
        clientSecret - The Client Secret.
        Returns:
        ServiceBuilder The service builder instance.
        Throws:
        java.lang.NullPointerException - If clientID or clientSecret is null.
        java.lang.IllegalArgumentException - If clientID or clientSecret is empty String.
      • getDebugOutputStream

        protected static java.io.OutputStream getDebugOutputStream()
        Gets the output stream for debugging.
        Returns:
        The output stream when debugging, or {code null} when not debugging.
      • getRequestAdditionalTime

        protected long getRequestAdditionalTime()
        The default additional required time in milliseconds to process a request, i.e. to see if an access token is still valid.

        Subclasses override this method to return another value.

        Returns:
        The default value of 20_000 milliseconds (20 seconds).
      • getLogoutURL

        public abstract java.lang.String getLogoutURL()
        Returns the logout URL for the OAuth service. It is not the same as invalidating an access URL.

        Subclasses must override this method and implement a return value.

        Returns:
        The logout URL, or null if none exists.
      • disposeBlocked

        public void disposeBlocked()
        Disposes of the session because of a blocked pop-up window. The listener is notified, if any.
        Specified by:
        disposeBlocked in interface IOAuthService
      • disposeUserCancel

        public void disposeUserCancel()
        Disposes of the session because of a user cancel action.
        Specified by:
        disposeUserCancel in interface IOAuthService
      • dispose

        public final void dispose()
        Disposes of the session, i.e. can e.g. close an asynchronous client in progress.
        Specified by:
        dispose in interface IOAuthService
      • doAuthenticate

        public void doAuthenticate​(IOAuthListener listener)
                            throws java.io.IOException,
                                   java.lang.InterruptedException,
                                   java.util.concurrent.ExecutionException
        Performs authentication.
        Parameters:
        listener - The listener for completion of the authentication progress.
        Throws:
        java.lang.NullPointerException - If service or listener is null.
        java.util.concurrent.ExecutionException - If execution failed when requesting the OAuth 1.0a request token.
        java.lang.InterruptedException - If thread was interrupted while waiting for the OAuth 1.0a request token.
        java.io.IOException - If an I/O error occurred during the the OAuth 1.0a request token.
        java.lang.IllegalStateException - If a call to this method doAuthenticate() has already been issued or the engine is not initialized.
      • getAccessToken

        protected final AccessToken getAccessToken()
                                            throws java.io.IOException,
                                                   java.lang.InterruptedException,
                                                   java.util.concurrent.ExecutionException
        Gets an access token, perhaps by means of refresh.
        Returns:
        The AccessToken instance.
        Throws:
        java.lang.IllegalStateException - If the authentication has not completed successfully.
        java.io.IOException - For I/O errors.
        java.util.concurrent.ExecutionException - If execution failed when requesting the token.
        java.lang.InterruptedException - If thread was interrupted while waiting for the token.
      • invalidateAccessToken

        public boolean invalidateAccessToken()
                                      throws java.util.concurrent.ExecutionException,
                                             java.lang.InterruptedException,
                                             java.io.IOException
        Invalidates the current Access Token that may be valid for quite some time.

        The last access token is revoked and this might lead to IOException's.

        For OAuth 1.0, this method just clears the Access Token so it has to be retrieved again and just returns false for failure.

        Returns:
        true for success, false for failure (no token to invalidate), or the service is of OAuth 1.0a type.
        Throws:
        java.util.concurrent.ExecutionException - For execution errors.
        java.lang.InterruptedException - If the revocation action was interrupted.
        java.io.IOException - For I/O errors.
      • getAccessToken2

        public final com.github.scribejava.core.model.OAuth2AccessToken getAccessToken2()
                                                                                 throws java.io.IOException,
                                                                                        java.lang.InterruptedException,
                                                                                        java.util.concurrent.ExecutionException
        Gets the current, refreshes or get a new OAuth 2.0 Access Token.
        Returns:
        The OAuth 2.0 Access Token instance.
        Throws:
        java.lang.IllegalStateException - If the authentication has not completed successfully.
        java.io.IOException - For I/O errors.
        java.util.concurrent.ExecutionException - If execution failed when requesting the token.
        java.lang.InterruptedException - If thread was interrupted while waiting for the token.
      • getAccessToken1

        public final com.github.scribejava.core.model.OAuth1AccessToken getAccessToken1()
                                                                                 throws java.io.IOException,
                                                                                        java.lang.InterruptedException,
                                                                                        java.util.concurrent.ExecutionException
        Gets the current, refreshes or get a new OAuth 1.0a Access Token.
        Returns:
        The OAuth 1.0a Access Token instance.
        Throws:
        java.lang.IllegalStateException - If the authentication has not completed successfully.
        java.io.IOException - For I/O errors.
        java.util.concurrent.ExecutionException - If execution failed when requesting the token.
        java.lang.InterruptedException - If thread was interrupted while waiting for the token.
      • getUserProfileInfo

        public abstract UserProfileInfo getUserProfileInfo()
                                                    throws java.io.IOException,
                                                           java.lang.InterruptedException,
                                                           java.util.concurrent.ExecutionException
        Gets the UserProfileInformation from this service.

        This will cause the user to have to authenticate with the service, unless not already done.

        All fields available for this service that are possible to set and available will be initialized. Other values will be left null, unknown or undefined.

        Returns:
        The UserProfileInfo instance.
        Throws:
        java.util.concurrent.ExecutionException - For execution errors.
        java.lang.InterruptedException - If the revocation action was interrupted.
        java.io.IOException - For I/O errors.