ParseAuthorizeResponse() public static method

public static ParseAuthorizeResponse ( string webAuthenticationResult, Microsoft.IdentityModel.Clients.ActiveDirectory.CallState callState ) : Microsoft.IdentityModel.Clients.ActiveDirectory.AuthorizationResult
webAuthenticationResult string
callState Microsoft.IdentityModel.Clients.ActiveDirectory.CallState
return Microsoft.IdentityModel.Clients.ActiveDirectory.AuthorizationResult
Beispiel #1
0
        public AuthorizationResult ProcessAuthorizationResult(IWebAuthenticationBrokerContinuationEventArgs args, CallState callState)
        {
            AuthorizationResult result;

            switch (args.WebAuthenticationResult.ResponseStatus)
            {
            case WebAuthenticationStatus.Success:
                result = OAuth2Response.ParseAuthorizeResponse(args.WebAuthenticationResult.ResponseData, callState);
                break;

            case WebAuthenticationStatus.ErrorHttp:
                result = new AuthorizationResult(AdalError.AuthenticationFailed, args.WebAuthenticationResult.ResponseErrorDetail.ToString());
                break;

            case WebAuthenticationStatus.UserCancel:
                result = new AuthorizationResult(AdalError.AuthenticationCanceled, AdalErrorMessage.AuthenticationCanceled);
                break;

            default:
                result = new AuthorizationResult(AdalError.AuthenticationFailed, AdalErrorMessage.AuthorizationServerInvalidResponse);
                break;
            }

            return(result);
        }
        public AuthorizationResult ProcessAuthorizationResult(IWebAuthenticationBrokerContinuationEventArgs args, CallState callState)
        {
            AuthorizationResult result;

            switch (args.WebAuthenticationResult.ResponseStatus)
            {
            case WebAuthenticationStatus.Success:
                // Issue #129 - Windows Phone cannot handle ms-app URI's so use the placeholder URI for SSO
                var responseData = args.WebAuthenticationResult.ResponseData;
                if (responseData.StartsWith(Constant.MsAppScheme, StringComparison.OrdinalIgnoreCase))
                {
                    responseData = Constant.SsoPlaceHolderUri + responseData.Substring(responseData.IndexOf('?'));
                }

                result = OAuth2Response.ParseAuthorizeResponse(responseData, callState);
                break;

            case WebAuthenticationStatus.ErrorHttp:
                result = new AuthorizationResult(AdalError.AuthenticationFailed, args.WebAuthenticationResult.ResponseErrorDetail.ToString());
                break;

            case WebAuthenticationStatus.UserCancel:
                result = new AuthorizationResult(AdalError.AuthenticationCanceled, AdalErrorMessage.AuthenticationCanceled);
                break;

            default:
                result = new AuthorizationResult(AdalError.AuthenticationFailed, AdalErrorMessage.AuthorizationServerInvalidResponse);
                break;
            }

            return(result);
        }
        internal void AcquireAuthorization()
        {
            var sendAuthorizeRequest = new Action(
                delegate
            {
                Uri authorizationUri     = this.CreateAuthorizationUri(IncludeFormsAuthParams());
                string resultUri         = this.webUi.Authenticate(authorizationUri, this.redirectUri);
                this.authorizationResult = OAuth2Response.ParseAuthorizeResponse(resultUri, this.CallState);
            });

            // If the thread is MTA, it cannot create or communicate with WebBrowser which is a COM control.
            // In this case, we have to create the browser in an STA thread via StaTaskScheduler object.
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
            {
                using (var staTaskScheduler = new StaTaskScheduler(1))
                {
                    Task.Factory.StartNew(sendAuthorizeRequest, CancellationToken.None, TaskCreationOptions.None, staTaskScheduler).Wait();
                }
            }
            else
            {
                sendAuthorizeRequest();
            }
        }