Skip to content

Commit ae843c6

Browse files
Pass through CancellationToken (#620)
Pass a CancellationToken through to more operations.
1 parent d8bd3eb commit ae843c6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/AspNet.Security.OAuth.Keycloak/KeycloakAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6161
"returned a {Status} response with the following payload: {Headers} {Body}.",
6262
/* Status: */ response.StatusCode,
6363
/* Headers: */ response.Headers.ToString(),
64-
/* Body: */ await response.Content.ReadAsStringAsync());
64+
/* Body: */ await response.Content.ReadAsStringAsync(Context.RequestAborted));
6565

6666
throw new HttpRequestException("An error occurred while retrieving the user profile from Keycloak.");
6767
}
6868

69-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
69+
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
7070
var principal = new ClaimsPrincipal(identity);
7171
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
7272
context.RunClaimActions();

src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Text;
1313
using System.Text.Encodings.Web;
1414
using System.Text.Json;
15+
using System.Threading;
1516
using System.Threading.Tasks;
1617
using JetBrains.Annotations;
1718
using Microsoft.AspNetCore.Authentication;
@@ -65,11 +66,11 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
6566
using var response = await Backchannel.SendAsync(requestMessage, Context.RequestAborted);
6667
if (response.IsSuccessStatusCode)
6768
{
68-
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
69+
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
6970
return OAuthTokenResponse.Success(payload);
7071
}
7172

72-
var error = "OAuth token endpoint failure: " + await DisplayAsync(response);
73+
var error = "OAuth token endpoint failure: " + await DisplayAsync(response, Context.RequestAborted);
7374
return OAuthTokenResponse.Failed(new Exception(error));
7475
}
7576

@@ -94,12 +95,12 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
9495
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
9596
}
9697

97-
private static async Task<string> DisplayAsync(HttpResponseMessage response)
98+
private static async Task<string> DisplayAsync(HttpResponseMessage response, CancellationToken cancellationToken)
9899
{
99100
var output = new StringBuilder();
100101
output.Append("Status: ").Append(response.StatusCode).Append(';');
101102
output.Append("Headers: ").Append(response.Headers).Append(';');
102-
output.Append("Body: ").Append(await response.Content.ReadAsStringAsync()).Append(';');
103+
output.Append("Body: ").Append(await response.Content.ReadAsStringAsync(cancellationToken)).Append(';');
103104
return output.ToString();
104105
}
105106
}

0 commit comments

Comments
 (0)