public async Task <AuthorizationResult> AcquireAuthorizationAsync(
            Uri authorizationUri,
            Uri redirectUri,
            RequestContext requestContext,
            CancellationToken cancellationToken)
        {
            var authCodeUri = await InterceptAuthorizationUriAsync(
                authorizationUri,
                redirectUri,
                cancellationToken)
                              .ConfigureAwait(true);


            if (!authCodeUri.Authority.Equals(redirectUri.Authority, StringComparison.OrdinalIgnoreCase) ||
                !authCodeUri.AbsolutePath.Equals(redirectUri.AbsolutePath))
            {
                throw new MsalClientException(
                          MsalError.LoopbackResponseUriMisatch,
                          MsalErrorMessage.RedirectUriMismatch(
                              authCodeUri.AbsolutePath,
                              redirectUri.AbsolutePath));
            }

            return(AuthorizationResult.FromUri(authCodeUri.OriginalString));
        }
        public async Task <AuthorizationResult> AcquireAuthorizationAsync(
            Uri authorizationUri,
            Uri redirectUri,
            RequestContext requestContext,
            CancellationToken cancellationToken)
        {
            try
            {
                var authCodeUri = await InterceptAuthorizationUriAsync(
                    authorizationUri,
                    redirectUri,
                    cancellationToken)
                                  .ConfigureAwait(true);

                if (!authCodeUri.Authority.Equals(redirectUri.Authority, StringComparison.OrdinalIgnoreCase) ||
                    !authCodeUri.AbsolutePath.Equals(redirectUri.AbsolutePath))
                {
                    throw new MsalClientException(
                              MsalError.LoopbackResponseUriMismatch,
                              MsalErrorMessage.RedirectUriMismatch(
                                  authCodeUri.AbsolutePath,
                                  redirectUri.AbsolutePath));
                }

                return(AuthorizationResult.FromUri(authCodeUri.OriginalString));
            }
            catch (System.Net.HttpListenerException) // sometimes this exception sneaks out (see issue 1773)
            {
                cancellationToken.ThrowIfCancellationRequested();
                throw;
            }
        }
        /// <inheritdoc />
        public async Task <AuthorizationResult> AcquireAuthorizationAsync(
            Uri authorizationUri,
            Uri redirectUri,
            RequestContext requestContext,
            CancellationToken cancellationToken)
        {
            requestContext.Logger.Info(LogMessages.CustomWebUiAcquiringAuthorizationCode);

            try
            {
                requestContext.Logger.InfoPii(LogMessages.CustomWebUiCallingAcquireAuthorizationCodePii(authorizationUri, redirectUri),
                                              LogMessages.CustomWebUiCallingAcquireAuthorizationCodeNoPii);
                var uri = await _customWebUi.AcquireAuthorizationCodeAsync(authorizationUri, redirectUri, cancellationToken)
                          .ConfigureAwait(false);

                if (uri == null || String.IsNullOrWhiteSpace(uri.Query))
                {
                    throw new MsalClientException(
                              MsalError.CustomWebUiReturnedInvalidUri,
                              MsalErrorMessage.CustomWebUiReturnedInvalidUri);
                }

                if (uri.Authority.Equals(redirectUri.Authority, StringComparison.OrdinalIgnoreCase) &&
                    uri.AbsolutePath.Equals(redirectUri.AbsolutePath))
                {
                    requestContext.Logger.Info(LogMessages.CustomWebUiRedirectUriMatched);
                    return(AuthorizationResult.FromUri(uri.OriginalString));
                }

                throw new MsalClientException(
                          MsalError.CustomWebUiRedirectUriMismatch,
                          MsalErrorMessage.RedirectUriMismatch(
                              uri.AbsolutePath,
                              redirectUri.AbsolutePath));
            }
            catch (OperationCanceledException)
            {
                requestContext.Logger.Info(LogMessages.CustomWebUiOperationCancelled);
                return(AuthorizationResult.FromStatus(AuthorizationStatus.UserCancel));
            }
            catch (Exception ex)
            {
                requestContext.Logger.WarningPiiWithPrefix(ex, MsalErrorMessage.CustomWebUiAuthorizationCodeFailed);
                throw;
            }
        }