Skip to content

Commit

Permalink
Restore Newtonsoft.Json
Browse files Browse the repository at this point in the history
Revert breaking change made in #70, instead making the new System.Text.Json support an addition, rather than a replacement.
  • Loading branch information
martincostello committed Mar 26, 2020
1 parent 5c5f596 commit fe99a43
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<AspNetCoreVersion>3.1.2</AspNetCoreVersion>
<IdentityModelCoreVersion>5.6.0</IdentityModelCoreVersion>
<JetBrainsVersion>2019.1.3</JetBrainsVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<JustEatHttpClientInterceptionVersion>3.0.0</JustEatHttpClientInterceptionVersion>
<MartinCostelloLoggingXUnitVersion>0.1.0</MartinCostelloLoggingXUnitVersion>
<ShouldlyVersion>3.0.2</ShouldlyVersion>
Expand Down
19 changes: 14 additions & 5 deletions src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;

namespace AspNet.Security.OpenId.Steam
{
Expand Down Expand Up @@ -100,10 +101,11 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

// Try to extract the profile name of the authenticated user.
var profile = payload.RootElement.GetProperty(SteamAuthenticationConstants.Parameters.Response)
.GetProperty(SteamAuthenticationConstants.Parameters.Players)
.EnumerateArray()
.FirstOrDefault();
var profile = payload.RootElement
.GetProperty(SteamAuthenticationConstants.Parameters.Response)
.GetProperty(SteamAuthenticationConstants.Parameters.Players)
.EnumerateArray()
.FirstOrDefault();

if (profile.ValueKind == JsonValueKind.Object && profile.TryGetProperty(SteamAuthenticationConstants.Parameters.Name, out var name))
{
Expand All @@ -116,9 +118,16 @@ async Task<AuthenticationTicket> RunAuthenticatedEventAsync(JsonDocument user =
{
var context = new OpenIdAuthenticatedContext(Context, Scheme, Options, ticket)
{
User = user
UserPayload = user
};

if (user != null)
{
#pragma warning disable CS0618
context.User = JObject.Parse(user.RootElement.ToString());
#pragma warning restore CS0618
}

// Copy the attributes to the context object.
foreach (var attribute in attributes)
{
Expand Down
1 change: 1 addition & 0 deletions src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="AngleSharp" Version="$(AngleSharpVersion)" />
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.IdentityModel.Protocols" Version="$(IdentityModelCoreVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
</ItemGroup>

Expand Down
11 changes: 10 additions & 1 deletion src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* for more information concerning the license and the contributors participating to this project.
*/

using System;
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
{
Expand Down Expand Up @@ -57,6 +59,13 @@ 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.
/// </summary>
public JsonDocument User { get; set; }
[Obsolete("Use the UserPayload property instead. This property's type will change from JObject to JsonDocument in a future release.")]
public JObject User { get; set; } = new JObject();

/// <summary>
/// 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.
/// </summary>
public JsonDocument UserPayload { get; set; }
}
}

0 comments on commit fe99a43

Please sign in to comment.