Search in sources :

Example 1 with CustomTabsManager

use of com.microsoft.identity.common.internal.ui.browser.CustomTabsManager in project microsoft-authentication-library-common-for-android by AzureAD.

the class CurrentTaskBrowserAuthorizationStrategy method requestAuthorization.

@Override
public Future<AuthorizationResult> requestAuthorization(GenericAuthorizationRequest authorizationRequest, GenericOAuth2Strategy oAuth2Strategy) throws ClientException {
    final String methodName = ":requestAuthorization";
    checkNotDisposed();
    final Context context = getApplicationContext();
    mOAuth2Strategy = oAuth2Strategy;
    mAuthorizationRequest = authorizationRequest;
    mAuthorizationResultFuture = new ResultFuture<>();
    final Browser browser = BrowserSelector.select(context, mBrowserSafeList);
    // ClientException will be thrown if no browser found.
    Intent authIntent;
    if (browser.isCustomTabsServiceSupported()) {
        Logger.info(TAG + methodName, "CustomTabsService is supported.");
        // create customTabsIntent
        mCustomTabManager = new CustomTabsManager(context);
        if (!mCustomTabManager.bind(context, browser.getPackageName())) {
            // create browser auth intent
            authIntent = new Intent(Intent.ACTION_VIEW);
        } else {
            authIntent = mCustomTabManager.getCustomTabsIntent().intent;
        }
    } else {
        Logger.warn(TAG + methodName, "CustomTabsService is NOT supported");
        // create browser auth intent
        authIntent = new Intent(Intent.ACTION_VIEW);
    }
    authIntent.setPackage(browser.getPackageName());
    final Uri requestUrl = authorizationRequest.getAuthorizationRequestAsHttpRequest();
    authIntent.setData(requestUrl);
    final Intent intent = buildAuthorizationActivityStartIntent(authIntent, requestUrl);
    launchIntent(intent);
    return mAuthorizationResultFuture;
}
Also used : Context(android.content.Context) CustomTabsManager(com.microsoft.identity.common.internal.ui.browser.CustomTabsManager) Intent(android.content.Intent) Uri(android.net.Uri) Browser(com.microsoft.identity.common.internal.ui.browser.Browser)

Aggregations

Context (android.content.Context)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Browser (com.microsoft.identity.common.internal.ui.browser.Browser)1 CustomTabsManager (com.microsoft.identity.common.internal.ui.browser.CustomTabsManager)1