Class OAuthLoginManager

  • public final class OAuthLoginManager
    extends Object
    Assists with the retrieval of an OAuthTokenCredential by launching an intent to show the OAuth login page in a device-installed browser app for custom OAuth workflows (those not already handled by the DefaultAuthenticationChallengeHandler). The redirect URI provided to this class (which must be declared in your redirect URI list on your application page) will be called with the resulting URI that contains the authorization URL. The application must declare an Activity and intent filter to handle this redirect URI. Once the intent has been intercepted, it can be passed to fetchOAuthTokenCredentialAsync(Intent). This will parse the authorization code from the response URI (or throw an exception if an error occurred) and use it to fetch an OAuthTokenCredential, this will then be placed in the AuthenticationManager's credential cache. The general workflow for using this class is as follows:
    1. OAuthLoginManager oAuthLoginManager = new OAuthLoginManager(context, portalUrl, clientId, redirectUri, expiration); // where portalUrl default value should be
    2. oAuthLoginManager.launchOAuthBrowserPage();
    3. Receive the resulting Intent in the activity declared in the manifest
    4. OAuthTokenCredential credential = oAuthLoginManager.fetchOAuthTokenCredentialAsync(intent)
    Note: As this class is only required for custom OAuth workflows not already provided by the DefaultAuthenticationChallengeHandler, it is not necessary to add OAuth configurations via AuthenticationManager.addOAuthConfiguration(OAuthConfiguration).
    See Also:
    AuthenticationManager, DefaultAuthenticationChallengeHandler
    • Constructor Detail

      • OAuthLoginManager

        public OAuthLoginManager​(String portalUrl,
                                 String clientId,
                                 String redirectUri,
                                 int expiration)
        Constructs an OAuthLoginManager with a Portal URL, the client ID registered to the application, the redirect URI that directs the result back into the application, and the expiration time for the refresh token.
        portalUrl - the URL of the portal, default to
        clientId - the client ID
        redirectUri - the redirect URI registered for the application
        expiration - the expiration of the refresh token in minutes. The refresh token can be valid for up to 90 days (129600 minutes) or the maximum limit set at the ArcGIS Online organisation level (whichever is minimum). Once the refresh token has expired, the user will have to log in again. For a permanent refresh token (if the portal supports it), use -1
    • Method Detail

      • launchOAuthBrowserPage

        public void launchOAuthBrowserPage​(android.content.Context context)
        Launches an intent to show the OAuth login page in a device installed browser. The parameters passed in the initialize method will be used to create the authorization URL to show. Once the user has logged in, the redirect URI will be called with an authorization code or error. The Activity declared in the manifest to intercept such intents can pass the resulting intent to fetchOAuthTokenCredentialAsync(Intent), which will parse the resulting URI for an authorization code and use it to fetch an OAuthTokenCredential, or throw an exception if there was an issue getting an authorization code or fetching the credential.
        context - the context used to launch the browser intent
      • fetchOAuthTokenCredentialAsync

        public ListenableFuture<OAuthTokenCredential> fetchOAuthTokenCredentialAsync​(android.content.Intent intent)
        Asynchronously fetches an OAuthTokenCredential using the response URI in the passed intent. If there was an error getting the authorization code, it will be thrown as an IOException. If there is an error fetching the OAuthTokenCredential with the successful authorization code, it will also throw an IOException.
        intent - the response intent from the browser that showed the OAuth login page
        a ListenableFuture for tracking when the computation is done and getting the result
        IOException - if there was an error getting the authorization code or OAuthTokenCredential