Skip to content

Commit

Permalink
Avoid KeyNotFoundException
Browse files Browse the repository at this point in the history
Resolves #769.
  • Loading branch information
martincostello committed Sep 14, 2024
1 parent 8b3e741 commit 75f4d3e
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
}

using var container = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
using var enumerator = container.RootElement.GetProperty("response").EnumerateArray();

if (!container.RootElement.TryGetProperty("response", out var profileResponse))
{
if (container.RootElement.TryGetProperty("error", out var error) &&
error.ValueKind is JsonValueKind.String)
{
throw new InvalidOperationException($"An error occurred while retrieving the user profile: {error.GetString()}");
}

throw new InvalidOperationException("An error occurred while retrieving the user profile.");
}

using var enumerator = profileResponse.EnumerateArray();
var payload = enumerator.First();

var principal = new ClaimsPrincipal(identity);
Expand Down

0 comments on commit 75f4d3e

Please sign in to comment.