Search in sources :

Example 1 with Browser

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

the class BrokerMsalController method logOutFromBrowser.

/**
 * Invoke the logout endpoint on the specified browser.
 * If there are more than 1 session in the browser, an account picker will be displayed.
 * (Alternatively, we could pass the optional sessionID as one of the query string parameter, but we're not storing that at the moment).
 *
 * @param context    {@link Context} application context.
 * @param parameters a {@link RemoveAccountCommandParameters}.
 */
private void logOutFromBrowser(@NonNull final Context context, @NonNull final RemoveAccountCommandParameters parameters) {
    final String methodName = ":logOutFromBrowser";
    String browserPackageName = null;
    try {
        final Browser browser = BrowserSelector.select(context, parameters.getBrowserSafeList());
        browserPackageName = browser.getPackageName();
    } catch (final ClientException e) {
        // Best effort. If none is passed to broker, then it will let the OS decide.
        Logger.error(TAG, e.getErrorCode(), e);
    }
    try {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(AuthenticationConstants.Browser.LOGOUT_ENDPOINT_V2));
        if (browserPackageName != null) {
            intent.setPackage(browserPackageName);
        }
        context.startActivity(intent);
    } catch (final ActivityNotFoundException e) {
        Logger.error(TAG + methodName, "Failed to launch browser sign out with browser=[" + browserPackageName + "]. Skipping.", e);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) ClientException(com.microsoft.identity.common.exception.ClientException) Browser(com.microsoft.identity.common.internal.ui.browser.Browser)

Example 2 with Browser

use of com.microsoft.identity.common.internal.ui.browser.Browser 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

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