Skip to content

Commit fe99a43

Browse files
Restore Newtonsoft.Json
Revert breaking change made in #70, instead making the new System.Text.Json support an addition, rather than a replacement.
1 parent 5c5f596 commit fe99a43

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<AspNetCoreVersion>3.1.2</AspNetCoreVersion>
1414
<IdentityModelCoreVersion>5.6.0</IdentityModelCoreVersion>
1515
<JetBrainsVersion>2019.1.3</JetBrainsVersion>
16+
<JsonNetVersion>10.0.3</JsonNetVersion>
1617
<JustEatHttpClientInterceptionVersion>3.0.0</JustEatHttpClientInterceptionVersion>
1718
<MartinCostelloLoggingXUnitVersion>0.1.0</MartinCostelloLoggingXUnitVersion>
1819
<ShouldlyVersion>3.0.2</ShouldlyVersion>

src/AspNet.Security.OpenId.Steam/SteamAuthenticationHandler.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.AspNetCore.WebUtilities;
1919
using Microsoft.Extensions.Logging;
2020
using Microsoft.Extensions.Options;
21+
using Newtonsoft.Json.Linq;
2122

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

102103
// Try to extract the profile name of the authenticated user.
103-
var profile = payload.RootElement.GetProperty(SteamAuthenticationConstants.Parameters.Response)
104-
.GetProperty(SteamAuthenticationConstants.Parameters.Players)
105-
.EnumerateArray()
106-
.FirstOrDefault();
104+
var profile = payload.RootElement
105+
.GetProperty(SteamAuthenticationConstants.Parameters.Response)
106+
.GetProperty(SteamAuthenticationConstants.Parameters.Players)
107+
.EnumerateArray()
108+
.FirstOrDefault();
107109

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

124+
if (user != null)
125+
{
126+
#pragma warning disable CS0618
127+
context.User = JObject.Parse(user.RootElement.ToString());
128+
#pragma warning restore CS0618
129+
}
130+
122131
// Copy the attributes to the context object.
123132
foreach (var attribute in attributes)
124133
{

src/AspNet.Security.OpenId/AspNet.Security.OpenId.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<PackageReference Include="AngleSharp" Version="$(AngleSharpVersion)" />
1616
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
1717
<PackageReference Include="Microsoft.IdentityModel.Protocols" Version="$(IdentityModelCoreVersion)" />
18+
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetVersion)" />
1819
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
1920
</ItemGroup>
2021

src/AspNet.Security.OpenId/Events/OpenIdAuthenticatedContext.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* for more information concerning the license and the contributors participating to this project.
55
*/
66

7+
using System;
78
using System.Collections.Generic;
89
using System.Security.Claims;
910
using System.Text.Json;
1011
using JetBrains.Annotations;
1112
using Microsoft.AspNetCore.Authentication;
1213
using Microsoft.AspNetCore.Http;
14+
using Newtonsoft.Json.Linq;
1315

1416
namespace AspNet.Security.OpenId
1517
{
@@ -57,6 +59,13 @@ public OpenIdAuthenticatedContext(
5759
/// Gets or sets the optional JSON payload extracted from the current request.
5860
/// This property is not set by the generic middleware but can be used by specialized middleware.
5961
/// </summary>
60-
public JsonDocument User { get; set; }
62+
[Obsolete("Use the UserPayload property instead. This property's type will change from JObject to JsonDocument in a future release.")]
63+
public JObject User { get; set; } = new JObject();
64+
65+
/// <summary>
66+
/// Gets or sets the optional JSON payload extracted from the current request.
67+
/// This property is not set by the generic middleware but can be used by specialized middleware.
68+
/// </summary>
69+
public JsonDocument UserPayload { get; set; }
6170
}
6271
}

0 commit comments

Comments
 (0)