8
8
using System . Net . Http . Headers ;
9
9
using System . Security . Claims ;
10
10
using System . Text . Encodings . Web ;
11
+ using System . Text . Json ;
11
12
using System . Threading . Tasks ;
12
13
using JetBrains . Annotations ;
13
14
using Microsoft . AspNetCore . Authentication ;
14
15
using Microsoft . AspNetCore . Authentication . OAuth ;
15
16
using Microsoft . AspNetCore . WebUtilities ;
16
17
using Microsoft . Extensions . Logging ;
17
18
using Microsoft . Extensions . Options ;
18
- using Newtonsoft . Json . Linq ;
19
19
20
20
namespace AspNet . Security . OAuth . < %= name % >
21
21
{
@@ -51,13 +51,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
51
51
// TODO Append any additional query string parameters required
52
52
//endpoint = QueryHelpers.AddQueryString(endpoint, "token", tokens.AccessToken);
53
53
54
- var request = new HttpRequestMessage ( HttpMethod . Get , endpoint ) ;
54
+ using var request = new HttpRequestMessage ( HttpMethod . Get , endpoint ) ;
55
55
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
56
56
57
57
// TODO Add any HTTP request headers required
58
58
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
59
59
60
- var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
60
+ using var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
61
61
if ( ! response . IsSuccessStatusCode )
62
62
{
63
63
Logger . LogError ( "An error occurred while retrieving the user profile: the remote server " +
@@ -69,11 +69,11 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
69
69
throw new HttpRequestException ( "An error occurred while retrieving the user profile from <%= name %>." ) ;
70
70
}
71
71
72
- var payload = JObject . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
72
+ using var payload = JsonDocument . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
73
73
74
74
var principal = new ClaimsPrincipal ( identity ) ;
75
- var context = new OAuthCreatingTicketContext ( principal , properties , Context , Scheme , Options , Backchannel , tokens , payload ) ;
76
- context . RunClaimActions ( payload ) ;
75
+ var context = new OAuthCreatingTicketContext ( principal , properties , Context , Scheme , Options , Backchannel , tokens , payload . RootElement ) ;
76
+ context . RunClaimActions ( ) ;
77
77
78
78
await Options . Events . CreatingTicket ( context ) ;
79
79
return new AuthenticationTicket ( context . Principal , context . Properties , Scheme . Name ) ;
0 commit comments