11
11
using IdentityServer4 . Configuration ;
12
12
using IdentityServer4 . Extensions ;
13
13
using IdentityServer4 . Models ;
14
+ using Microsoft . AspNetCore . DataProtection . KeyManagement ;
14
15
using Microsoft . AspNetCore . Http ;
15
16
using Microsoft . Extensions . Logging ;
16
17
using Microsoft . IdentityModel . Tokens ;
@@ -26,7 +27,7 @@ public class JwtRequestValidator
26
27
{
27
28
private readonly string _audienceUri ;
28
29
private readonly IHttpContextAccessor _httpContextAccessor ;
29
-
30
+
30
31
/// <summary>
31
32
/// JWT handler
32
33
/// </summary>
@@ -55,7 +56,7 @@ protected string AudienceUri
55
56
/// The logger
56
57
/// </summary>
57
58
protected readonly ILogger Logger ;
58
-
59
+
59
60
/// <summary>
60
61
/// The optione
61
62
/// </summary>
@@ -67,7 +68,7 @@ protected string AudienceUri
67
68
public JwtRequestValidator ( IHttpContextAccessor contextAccessor , IdentityServerOptions options , ILogger < JwtRequestValidator > logger )
68
69
{
69
70
_httpContextAccessor = contextAccessor ;
70
-
71
+
71
72
Options = options ;
72
73
Logger = logger ;
73
74
}
@@ -181,8 +182,8 @@ protected virtual Task<JwtSecurityToken> ValidateJwtAsync(string jwtTokenString,
181
182
}
182
183
183
184
Handler . ValidateToken ( jwtTokenString , tokenValidationParameters , out var token ) ;
184
-
185
- return Task . FromResult ( ( JwtSecurityToken ) token ) ;
185
+
186
+ return Task . FromResult ( ( JwtSecurityToken ) token ) ;
186
187
}
187
188
188
189
/// <summary>
@@ -200,17 +201,18 @@ protected virtual Task<Dictionary<string, string>> ProcessPayloadAsync(JwtSecuri
200
201
{
201
202
var value = token . Payload [ key ] ;
202
203
203
- switch ( value )
204
+ if ( value is string )
205
+ {
206
+ payload . Add ( key , value . ToString ( ) ) ;
207
+ }
208
+ else
204
209
{
205
- case string s :
206
- payload . Add ( key , s ) ;
207
- break ;
208
- case JObject jobj :
209
- payload . Add ( key , jobj . ToString ( Formatting . None ) ) ;
210
- break ;
211
- case JArray jarr :
212
- payload . Add ( key , jarr . ToString ( Formatting . None ) ) ;
213
- break ;
210
+ var valueType = value . GetType ( ) ;
211
+ if ( valueType . Name == "JObject" || // Microsoft.IdentityModel.Json.Linq.JObject
212
+ valueType . Name == "JArray" ) // Microsoft.IdentityModel.Json.Linq.JArray
213
+ {
214
+ payload . Add ( key , value . ToString ( ) ) ;
215
+ }
214
216
}
215
217
}
216
218
}
0 commit comments