diff --git a/eng/Versions.props b/eng/Versions.props index 2983c139..36756f12 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -13,9 +13,9 @@ 3.0.0 2.1.4 2019.1.3 - 10.0.3 3.0.0 0.1.0 3.0.2 + 4.6.0 diff --git a/src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs b/src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs index ce707208..a4c48e00 100644 --- a/src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs +++ b/src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs @@ -6,17 +6,18 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Security.Claims; using System.Text.Encodings.Web; +using System.Text.Json; using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json.Linq; namespace AspNet.Security.OpenId.Steam { @@ -96,25 +97,26 @@ protected override async Task CreateTicketAsync( throw new HttpRequestException("An error occurred while retrieving the user profile from Steam."); } - var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); + using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); // Try to extract the profile name of the authenticated user. - var profile = payload.Value(SteamAuthenticationConstants.Parameters.Response) - ?.Value(SteamAuthenticationConstants.Parameters.Players) - ?[0]?.Value(SteamAuthenticationConstants.Parameters.Name); + var profile = payload.RootElement.GetProperty(SteamAuthenticationConstants.Parameters.Response) + .GetProperty(SteamAuthenticationConstants.Parameters.Players) + .EnumerateArray() + .FirstOrDefault(); - if (!string.IsNullOrEmpty(profile)) + if (profile.ValueKind == JsonValueKind.Object && profile.TryGetProperty(SteamAuthenticationConstants.Parameters.Name, out var name)) { - identity.AddClaim(new Claim(ClaimTypes.Name, profile, ClaimValueTypes.String, Options.ClaimsIssuer)); + identity.AddClaim(new Claim(ClaimTypes.Name, name.GetString(), ClaimValueTypes.String, Options.ClaimsIssuer)); } return await RunAuthenticatedEventAsync(payload); - async Task RunAuthenticatedEventAsync(JObject user = null) + async Task RunAuthenticatedEventAsync(JsonDocument user = null) { var context = new OpenIdAuthenticatedContext(Context, Scheme, Options, ticket) { - User = user ?? new JObject() + User = user }; // Copy the attributes to the context object. diff --git a/src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj b/src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj index 53c9dc9b..28fb27f6 100644 --- a/src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj +++ b/src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs b/src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs index 7b486345..117fb9c9 100644 --- a/src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs +++ b/src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs @@ -6,10 +6,10 @@ using System.Collections.Generic; using System.Security.Claims; +using System.Text.Json; using JetBrains.Annotations; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; -using Newtonsoft.Json.Linq; namespace AspNet.Security.OpenId { @@ -57,6 +57,6 @@ public OpenIdAuthenticatedContext( /// Gets or sets the optional JSON payload extracted from the current request. /// This property is not set by the generic middleware but can be used by specialized middleware. /// - public JObject User { get; set; } = new JObject(); + public JsonDocument User { get; set; } } }