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;
        }
        public static void SetAuthenticationAgentContinuationEventArgs(int requestCode, Result resultCode, Intent data)
        {
            AuthorizationResult authorizationResult;
            switch (resultCode)
            {
                case Result.Ok: authorizationResult= new AuthorizationResult(AuthorizationStatus.Success, data.GetStringExtra("ReturnedUrl")); break;
                case Result.Canceled: authorizationResult = new AuthorizationResult(AuthorizationStatus.UserCancel, null); break;
                default: authorizationResult = new AuthorizationResult(AuthorizationStatus.UnknownError, null); break;
            }

            WebUI.SetAuthorizationResult(authorizationResult);
        }
Exemple #3
0
        public static void SetAuthorizationResultUri(WebAuthenticationResult webAuthenticationResult)
        {
            switch (webAuthenticationResult.ResponseStatus)
            {
                case WebAuthenticationStatus.Success:
                    authorizationResult = new AuthorizationResult(AuthorizationStatus.Success, webAuthenticationResult.ResponseData);
                    break;
                case WebAuthenticationStatus.ErrorHttp:
                    authorizationResult = new AuthorizationResult(AuthorizationStatus.ErrorHttp, null);
                    break;
                case WebAuthenticationStatus.UserCancel:
                    authorizationResult = new AuthorizationResult(AuthorizationStatus.UserCancel, null);
                    break;
                default:
                    authorizationResult = new AuthorizationResult(AuthorizationStatus.UnknownError, null);
                    break;
            }

            returnedUriReady.Release();
        }
        public void Authenticate(Uri authorizationUri, Uri redirectUri, IDictionary<string, object> headersMap, CallState callState)
        {
            string key = authorizationUri.AbsoluteUri + redirectUri.AbsoluteUri;

            LastAuthorizationResult = null;
            if (IOMap.ContainsKey(key))
            {
                string value = IOMap[key];
                if (value[0] == 'P')
                {
                    LastAuthorizationResult = OAuth2Response.ParseAuthorizeResponse(value.Substring(1), callState);
                }
                else if (value[0] == 'A')
                {
                    string[] segments = value.Substring(1).Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries);
                    LastAuthorizationResult = new AuthorizationResult(error: segments[0], errorDescription: segments[1]);
                }
            }

            LastHeadersMap = headersMap;
        }
        public static AuthorizationResult ParseAuthorizeResponse(string webAuthenticationResult, CallState callState)
        {
            AuthorizationResult result = null;

            var resultUri = new Uri(webAuthenticationResult);

            // NOTE: The Fragment property actually contains the leading '#' character and that must be dropped
            string resultData = resultUri.Query;

            if (!string.IsNullOrWhiteSpace(resultData))
            {
                // Remove the leading '?' first
                Dictionary<string, string> response = EncodingHelper.ParseKeyValueList(resultData.Substring(1), '&', true, callState);

                if (response.ContainsKey(OAuthReservedClaim.Code))
                {
                    result = new AuthorizationResult(response[OAuthReservedClaim.Code]);
                }
                else if (response.ContainsKey(OAuthReservedClaim.Error))
                {
                    result = new AuthorizationResult(response[OAuthReservedClaim.Error], response.ContainsKey(OAuthReservedClaim.ErrorDescription) ? response[OAuthReservedClaim.ErrorDescription] : null);
                }
                else
                {
                    result = new AuthorizationResult(AdalError.AuthenticationFailed, AdalErrorMessage.AuthorizationServerInvalidResponse);
                }
            }

            return result;
        }
 internal async Task AcquireAuthorizationAsync()
 {
     Uri authorizationUri = this.CreateAuthorizationUri();
     this.authorizationResult = await this.webUi.AcquireAuthorizationAsync(authorizationUri, this.redirectUri, this.CallState);
 }
        private static AuthorizationResult ProcessAuthorizationResult(WebAuthenticationResult webAuthenticationResult, CallState callState)
        {
            AuthorizationResult result;
            switch (webAuthenticationResult.ResponseStatus)
            {
                case WebAuthenticationStatus.Success:
                    result = OAuth2Response.ParseAuthorizeResponse(webAuthenticationResult.ResponseData, callState);
                    break;
                case WebAuthenticationStatus.ErrorHttp:
                    result = new AuthorizationResult(AdalError.AuthenticationFailed, 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;
        }
Exemple #8
0
        private static AuthorizationResult ProcessAuthorizationResult(WebAuthenticationResult webAuthenticationResult, CallState callState)
        {
            AuthorizationResult result;
            switch (webAuthenticationResult.ResponseStatus)
            {
                case WebAuthenticationStatus.Success:
                    result = new AuthorizationResult(AuthorizationStatus.Success, webAuthenticationResult.ResponseData);
                    break;
                case WebAuthenticationStatus.ErrorHttp:
                    result = new AuthorizationResult(AuthorizationStatus.ErrorHttp, webAuthenticationResult.ResponseErrorDetail.ToString());
                    break;
                case WebAuthenticationStatus.UserCancel:
                    result = new AuthorizationResult(AuthorizationStatus.UserCancel, null);
                    break;
                default:
                    result = new AuthorizationResult(AuthorizationStatus.UnknownError, null);
                    break;
            }

            return result;
        }
Exemple #9
0
 public static void SetAuthorizationResult(AuthorizationResult authorizationResultInput)
 {
     authorizationResult = authorizationResultInput;
     returnedUriReady.Release();
 }
Exemple #10
0
 private void CallbackMethod(AuthorizationResult result)
 {
     SetAuthorizationResult(result);
 }