Class OAuth2BrowserProcessor

  • All Implemented Interfaces:

    
    public class OAuth2BrowserProcessor
    extends OAuth2Processor
                        

    Handles authentication with OAuth2. The default browser will be used if it matches the browser whitelist. A custom tab will be used instead of a standalone browser, if the default browser supports it. If there is no default browser, a browser matching the whitelist that supports custom tabs will be chosen if one exists (with preference given to Chrome if multiple browsers meet that criteria). Otherwise, any browser matching the whitelist will be chosen. If there are no browsers installed that are allowed by the whitelist then authentication will fail. This class is meant to be used with OAuth2Interceptor.

    
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .addInterceptor(
            new OAuth2Interceptor(
                new OAuth2BrowserProcessor(oauthConfiguration),
                tokenStore))
        .cookieJar(new WebkitCookieJar())
        .build();
    
    • Constructor Detail

      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuth2Configuration oauth2Configuration)
        Parameters:
        oauth2Configuration - Contains the configuration information.
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuth2Configuration oauth2Configuration, OkHttpClient client)
        Parameters:
        oauth2Configuration - Contains the configuration information.
        client - The OkHttpClient that will be used to make requests.
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuth2Configuration oauth2Configuration, OkHttpClient client, BrowserWhitelist browserWhitelist)
        Parameters:
        oauth2Configuration - Contains the configuration information.
        client - The OkHttpClient that will be used to make requests.
        browserWhitelist - The BrowserWhitelist that will be used when selecting the browser used to perform the OAuth flow.
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuth2Configuration oauth2Configuration, BrowserWhitelist browserWhitelist)
        Parameters:
        oauth2Configuration - Contains the configuration information.
        browserWhitelist - The BrowserWhitelist that will be used when selecting the browser used to perform the OAuth flow.
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuthConfig oAuthConfig)
        Constructs a new OAuth2BrowserProcessor.
        Parameters:
        oAuthConfig - the OAuth configuration
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuthConfig oAuthConfig, AbstractOAuthClient oAuthClient, OkHttpClient client)
        Constructs a new OAuth2BrowserProcessor.
        Parameters:
        oAuthConfig - the OAuth configuration
        oAuthClient - the AbstractOAuthClient used as OAuth credentials
        client - the OkHttpClient used to make requests
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuthConfig oAuthConfig, AbstractOAuthClient oAuthClient, OkHttpClient client, OAuth2WebOption authOption)
        Constructs a new OAuth2BrowserProcessor.
        Parameters:
        oAuthConfig - the OAuth configuration
        oAuthClient - the AbstractOAuthClient used as OAuth credentials
        client - the OkHttpClient used to make requests
        authOption - 0: CCT, 1: Browser
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuthConfig oAuthConfig, AbstractOAuthClient oAuthClient, OkHttpClient client, OAuth2WebOption authOption, BrowserWhitelist browserWhitelist)
        Constructs a new OAuth2BrowserProcessor.
        Parameters:
        oAuthConfig - the OAuth configuration
        oAuthClient - the AbstractOAuthClient used as OAuth credentials
        client - the OkHttpClient used to make requests
        authOption - The authentication option, CCT or WebView
        browserWhitelist - the browser white list.
      • OAuth2BrowserProcessor

        OAuth2BrowserProcessor(OAuthConfig oAuthConfig, AbstractOAuthClient oAuthClient, OkHttpClient client, BrowserWhitelist browserWhitelist)
        Constructs a new OAuth2BrowserProcessor.
        Parameters:
        oAuthConfig - the OAuth configuration
        oAuthClient - the AbstractOAuthClient used as OAuth credentials
        client - the OkHttpClient used to make requests
        browserWhitelist - The BrowserWhitelist used when selecting the browser to perform the OAuth flow
    • Method Detail

      • authenticate

        @Nullable()@WorkerThread() OAuth2Token authenticate()

        Starts the OAuth 2.0 authentication process.

        Returns:

        The obtained OAuth2Token if the process was successful, otherwise null.

      • cancelAuthentication

         void cancelAuthentication()

        Cancels the ongoing authentication process. Does nothing if there was no ongoing authentication.