diff --git a/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs index 9bacf18a5..ada3c38e6 100644 --- a/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs @@ -49,7 +49,19 @@ protected override async Task 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);