Skip to content

Commit 67f41f9

Browse files
authored
improves efficiency parsing Response (#890)
1 parent 5b4b2f1 commit 67f41f9

File tree

85 files changed

+194
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+194
-105
lines changed

src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4242
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4343
}
4444

45-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
45+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
46+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4647

4748
var principal = new ClaimsPrincipal(identity);
4849
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5757
throw new HttpRequestException("An error occurred while retrieving the user profile from Amazon.");
5858
}
5959

60-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
60+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
61+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
6162

6263
var principal = new ClaimsPrincipal(identity);
6364
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5151
throw new HttpRequestException("An error occurred while retrieving the user profile from amoCRM.");
5252
}
5353

54-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
54+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
55+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
5556

5657
var principal = new ClaimsPrincipal(identity);
5758
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4343

4444
// Request the token
4545
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
46-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
46+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
47+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4748

4849
// Note: error responses always return 200 status codes.
4950
if (payload.RootElement.TryGetProperty("error", out var error))

src/AspNet.Security.OAuth.Asana/AsanaAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Autodesk/AutodeskAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4040
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4141
}
4242

43-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
43+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
44+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4445

4546
var principal = new ClaimsPrincipal(identity);
4647
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4141
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4242
}
4343

44-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
44+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
45+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4546

4647
var principal = new ClaimsPrincipal(identity);
4748
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Basecamp/BasecampAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4141
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4242
}
4343

44-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
44+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
45+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4546

4647
var principal = new ClaimsPrincipal(identity);
4748
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
@@ -76,7 +77,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
7677
throw new HttpRequestException("An error occurred while retrieving the email address associated to the user profile.");
7778
}
7879

79-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
80+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
81+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
8082

8183
return (from address in payload.RootElement.GetProperty("values").EnumerateArray()
8284
where address.GetProperty("is_primary").GetBoolean()

src/AspNet.Security.OAuth.Buffer/BufferAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.CiscoSpark/CiscoSparkAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement.GetProperty("data"));

src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
5555
return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an OAuth token."));
5656
}
5757

58-
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
58+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
59+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
5960
return OAuthTokenResponse.Success(payload);
6061
}
6162

@@ -76,7 +77,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
7677
throw new HttpRequestException("An error occurred while retrieving the user profile.");
7778
}
7879

79-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
80+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
81+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
8082

8183
var principal = new ClaimsPrincipal(identity);
8284
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.DeviantArt/DeviantArtAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
7575
throw new HttpRequestException("An error occurred while retrieving the user profile.");
7676
}
7777

78-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
78+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
79+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
7980

8081
var account = payload.RootElement.GetProperty("account");
8182

src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5555
throw new HttpRequestException("An error occurred while retrieving the user profile.");
5656
}
5757

58-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
58+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
59+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
5960

6061
var principal = new ClaimsPrincipal(identity);
6162
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5555
throw new HttpRequestException("An error occurred while retrieving the user profile.");
5656
}
5757

58-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
58+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
59+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
5960

6061
var principal = new ClaimsPrincipal(identity);
6162
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
3737
throw new HttpRequestException("An error occurred while retrieving the user profile.");
3838
}
3939

40-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
40+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
41+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4142

4243
var principal = new ClaimsPrincipal(identity);
4344
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
@@ -82,7 +83,8 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
8283
return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an access token."));
8384
}
8485

85-
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
86+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
87+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
8688

8789
return OAuthTokenResponse.Success(payload);
8890
}

src/AspNet.Security.OAuth.ExactOnline/ExactOnlineAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4040
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4141
}
4242

43-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
43+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
44+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4445
var user = payload.RootElement
4546
.GetProperty("d")
4647
.GetProperty("results")

src/AspNet.Security.OAuth.Feishu/FeishuAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3939
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4040
}
4141

42-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
42+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
43+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4344

4445
var principal = new ClaimsPrincipal(identity);
4546
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4040
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4141
}
4242

43-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
43+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
44+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
4445

4546
var principal = new ClaimsPrincipal(identity);
4647
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
@@ -79,7 +80,8 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
7980
return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an access token."));
8081
}
8182

82-
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
83+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
84+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
8385

8486
return OAuthTokenResponse.Success(payload);
8587
}

src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4848
throw new HttpRequestException("An error occurred while retrieving the user profile.");
4949
}
5050

51-
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
51+
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
52+
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
5253

5354
var principal = new ClaimsPrincipal(identity);
5455
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);

0 commit comments

Comments
 (0)