Search in sources :

Example 1 with PKeyAuthChallengeHandler

use of com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallengeHandler in project microsoft-authentication-library-common-for-android by AzureAD.

the class AzureActiveDirectoryWebViewClient method handleUrl.

/**
 * Interpret and take action on a redirect url.
 * This function will return true in every case save 1.  That is, when the URL is none of:
 * <ul><li>A urn containing an authorization challenge (starts with "urn:http-auth:PKeyAuth")</li>
 * <li>A url that starts with the same prefix as the tenant's redirect url</li>
 * <li>An explicit request to open the browser (starts with "browser://")</li>
 * <li>A request to install the auth broker (starts with "msauth://")</li>
 * <li>A request from WebCP (starts with "companyportal://")</li>
 * <li>It is a request that has the intent of starting the broker and the url starts with "browser://"</li>
 * <li>It <strong>does not</strong> begin with "https://".</li></ul>
 *
 * @param view The WebView that is initiating the callback.
 * @param url  The string representation of the url.
 * @return false if we will not take action on the url.
 */
private boolean handleUrl(final WebView view, final String url) {
    final String formattedURL = url.toLowerCase(Locale.US);
    if (isPkeyAuthUrl(formattedURL)) {
        Logger.info(TAG, "WebView detected request for pkeyauth challenge.");
        try {
            final PKeyAuthChallengeFactory factory = new PKeyAuthChallengeFactory();
            final PKeyAuthChallenge pKeyAuthChallenge = factory.getPKeyAuthChallenge(url);
            final PKeyAuthChallengeHandler pKeyAuthChallengeHandler = new PKeyAuthChallengeHandler(view, getCompletionCallback());
            pKeyAuthChallengeHandler.processChallenge(pKeyAuthChallenge);
        } catch (final ClientException exception) {
            Logger.error(TAG, exception.getErrorCode(), null);
            Logger.errorPII(TAG, exception.getMessage(), exception);
            returnError(exception.getErrorCode(), exception.getMessage());
            view.stopLoading();
        }
    } else if (isRedirectUrl(formattedURL)) {
        Logger.info(TAG, "Navigation starts with the redirect uri.");
        processRedirectUrl(view, url);
    } else if (isWebsiteRequestUrl(formattedURL)) {
        Logger.info(TAG, "It is an external website request");
        processWebsiteRequest(view, url);
    } else if (isInstallRequestUrl(formattedURL)) {
        Logger.info(TAG, "It is an install request");
        processInstallRequest(view, url);
    } else if (isWebCpUrl(formattedURL)) {
        Logger.info(TAG, "It is a request from WebCP");
        processWebCpRequest(view, url);
    } else if (isPlayStoreUrl(formattedURL)) {
        Logger.info(TAG, "Request to open PlayStore.");
        return processPlayStoreURL(view, url);
    } else if (isAuthAppMFAUrl(formattedURL)) {
        Logger.info(TAG, "Request to link account with Authenticator.");
        processAuthAppMFAUrl(url);
    } else if (isInvalidRedirectUri(url)) {
        Logger.info(TAG, "Check for Redirect Uri.");
        processInvalidRedirectUri(view, url);
    } else if (isBlankPageRequest(formattedURL)) {
        Logger.info(TAG, "It is an blank page request");
    } else if (isUriSSLProtected(formattedURL)) {
        Logger.info(TAG, "Check for SSL protection");
        processSSLProtectionCheck(view, url);
    } else {
        Logger.info(TAG, "This maybe a valid URI, but no special handling for this mentioned URI, hence deferring to WebView for loading.");
        processInvalidUrl(url);
        return false;
    }
    return true;
}
Also used : PKeyAuthChallenge(com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallenge) PKeyAuthChallengeFactory(com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallengeFactory) PKeyAuthChallengeHandler(com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallengeHandler) ClientException(com.microsoft.identity.common.exception.ClientException)

Aggregations

ClientException (com.microsoft.identity.common.exception.ClientException)1 PKeyAuthChallenge (com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallenge)1 PKeyAuthChallengeFactory (com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallengeFactory)1 PKeyAuthChallengeHandler (com.microsoft.identity.common.internal.ui.webview.challengehandlers.PKeyAuthChallengeHandler)1