-
Notifications
You must be signed in to change notification settings - Fork 551
Open
Labels
Description
AFAICT, LineAuthenticationHandler.ExchangeCodeAsync()
doesn't seem to do anything special so it's probably not necessary.
AspNet.Security.OAuth.Providers/src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs
Lines 35 to 66 in cbbc7a1
protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OAuthCodeExchangeContext context) | |
{ | |
var tokenRequestParameters = new Dictionary<string, string> | |
{ | |
["grant_type"] = "authorization_code", | |
["code"] = context.Code, | |
["redirect_uri"] = context.RedirectUri, | |
["client_id"] = Options.ClientId, | |
["client_secret"] = Options.ClientSecret, | |
}; | |
// PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl | |
if (context.Properties.Items.TryGetValue(OAuthConstants.CodeVerifierKey, out var codeVerifier)) | |
{ | |
tokenRequestParameters.Add(OAuthConstants.CodeVerifierKey, codeVerifier!); | |
context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey); | |
} | |
using var request = new HttpRequestMessage(HttpMethod.Post, Options.TokenEndpoint); | |
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
request.Content = new FormUrlEncodedContent(tokenRequestParameters); | |
using var response = await Backchannel.SendAsync(request, Context.RequestAborted); | |
if (!response.IsSuccessStatusCode) | |
{ | |
await Log.ExchangeCodeErrorAsync(Logger, response, Context.RequestAborted); | |
return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an access token.")); | |
} | |
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted)); | |
return OAuthTokenResponse.Success(payload); | |
} |