Skip to content

Commit

Permalink
Fix AuthResult parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak committed Jul 20, 2021
1 parent 4f5d7a0 commit bf80f08
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions src/client/Microsoft.Identity.Client/UI/AuthorizationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,7 @@ public static AuthorizationResult FromUri(string webAuthenticationResult)
Dictionary<string, string> uriParams = CoreHelpers.ParseKeyValueList(
resultData.Substring(1), '&', true, null);

var authResult = FromParsedValues(uriParams);

if (uriParams.ContainsKey(TokenResponseClaim.Code))
{
authResult.Code = uriParams[TokenResponseClaim.Code];
}
else if (webAuthenticationResult.StartsWith("msauth://", StringComparison.OrdinalIgnoreCase))
{
authResult.Code = webAuthenticationResult;
}
else
{
return FromStatus(
AuthorizationStatus.UnknownError,
MsalError.AuthenticationFailed,
MsalErrorMessage.AuthorizationServerInvalidResponse);
}

return authResult;
return FromParsedValues(uriParams, webAuthenticationResult);
}

public static AuthorizationResult FromPostData(byte[] postData)
Expand Down Expand Up @@ -101,7 +83,7 @@ public static AuthorizationResult FromPostData(byte[] postData)
return result;
}

private static AuthorizationResult FromParsedValues(Dictionary<string, string> parameters)
private static AuthorizationResult FromParsedValues(Dictionary<string, string> parameters, string url = null)
{
if (parameters.ContainsKey(TokenResponseClaim.Error))
{
Expand All @@ -112,27 +94,43 @@ private static AuthorizationResult FromParsedValues(Dictionary<string, string> p
: null);
}

var result = new AuthorizationResult
var authResult = new AuthorizationResult
{
Status = AuthorizationStatus.Success
};

if (parameters.ContainsKey(OAuth2Parameter.State))
{
result.State = parameters[OAuth2Parameter.State];
authResult.State = parameters[OAuth2Parameter.State];
}

if (parameters.ContainsKey(TokenResponseClaim.CloudInstanceHost))
{
result.CloudInstanceHost = parameters[TokenResponseClaim.CloudInstanceHost];
authResult.CloudInstanceHost = parameters[TokenResponseClaim.CloudInstanceHost];
}

if (parameters.ContainsKey(TokenResponseClaim.ClientInfo))
{
result.ClientInfo = parameters[TokenResponseClaim.ClientInfo];
authResult.ClientInfo = parameters[TokenResponseClaim.ClientInfo];
}

return result;
if (parameters.ContainsKey(TokenResponseClaim.Code))
{
authResult.Code = parameters[TokenResponseClaim.Code];
}
else if (!string.IsNullOrEmpty(url) && url.StartsWith("msauth://", StringComparison.OrdinalIgnoreCase))
{
authResult.Code = url;
}
else
{
return FromStatus(
AuthorizationStatus.UnknownError,
MsalError.AuthenticationFailed,
MsalErrorMessage.AuthorizationServerInvalidResponse);
}

return authResult;
}

internal static AuthorizationResult FromStatus(AuthorizationStatus status)
Expand Down

0 comments on commit bf80f08

Please sign in to comment.