88using System . Net . Http . Headers ;
99using System . Security . Claims ;
1010using System . Text . Encodings . Web ;
11+ using System . Text . Json ;
1112using System . Threading . Tasks ;
1213using JetBrains . Annotations ;
1314using Microsoft . AspNetCore . Authentication ;
1415using Microsoft . AspNetCore . Authentication . OAuth ;
1516using Microsoft . AspNetCore . WebUtilities ;
1617using Microsoft . Extensions . Logging ;
1718using Microsoft . Extensions . Options ;
18- using Newtonsoft . Json . Linq ;
1919
2020namespace AspNet . Security . OAuth . < %= name % >
2121{
@@ -51,13 +51,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5151 // TODO Append any additional query string parameters required
5252 //endpoint = QueryHelpers.AddQueryString(endpoint, "token", tokens.AccessToken);
5353
54- var request = new HttpRequestMessage ( HttpMethod . Get , endpoint ) ;
54+ using var request = new HttpRequestMessage ( HttpMethod . Get , endpoint ) ;
5555 request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
5656
5757 // TODO Add any HTTP request headers required
5858 //request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
5959
60- var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
60+ using var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
6161 if ( ! response . IsSuccessStatusCode )
6262 {
6363 Logger . LogError ( "An error occurred while retrieving the user profile: the remote server " +
@@ -69,11 +69,11 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6969 throw new HttpRequestException ( "An error occurred while retrieving the user profile from <%= name %>." ) ;
7070 }
7171
72- var payload = JObject . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
72+ using var payload = JsonDocument . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
7373
7474 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 ( ) ;
7777
7878 await Options . Events . CreatingTicket ( context ) ;
7979 return new AuthenticationTicket ( context . Principal , context . Properties , Scheme . Name ) ;
0 commit comments