Exemplo n.º 1
0
        public void ParseAuthorizeResponse(string webAuthenticationResult)
        {
            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 = MsalHelpers.ParseKeyValueList(resultData.Substring(1), '&',
                                                                                     true, null);

                if (response.ContainsKey(OAuth2Parameter.State))
                {
                    State = response[OAuth2Parameter.State];
                }

                if (response.ContainsKey(TokenResponseClaim.Code))
                {
                    Code = response[TokenResponseClaim.Code];
                }
                else if (response.ContainsKey(TokenResponseClaim.Error))
                {
                    Error            = response[TokenResponseClaim.Error];
                    ErrorDescription = response.ContainsKey(TokenResponseClaim.ErrorDescription)
                        ? response[TokenResponseClaim.ErrorDescription]
                        : null;
                    Status = AuthorizationStatus.ProtocolError;
                }
                else
                {
                    Error            = MsalError.AuthenticationFailed;
                    ErrorDescription = MsalErrorMessage.AuthorizationServerInvalidResponse;
                    Status           = AuthorizationStatus.UnknownError;
                }
            }
            else
            {
                Error            = MsalError.AuthenticationFailed;
                ErrorDescription = MsalErrorMessage.AuthorizationServerInvalidResponse;
                Status           = AuthorizationStatus.UnknownError;
            }
        }
Exemplo n.º 2
0
 public static string DecodeToString(string arg)
 {
     byte[] decoded = DecodeToBytes(arg);
     return(MsalHelpers.CreateString(decoded));
 }