Skip to content

Commit

Permalink
Revert JSON serialization refactoring (#901)
Browse files Browse the repository at this point in the history
This reverts commit 67f41f9 from #890.
  • Loading branch information
martincostello authored Jun 13, 2024
1 parent 650716b commit 4bee700
Show file tree
Hide file tree
Showing 85 changed files with 105 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile from Amazon.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile from amoCRM.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(

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

// Note: error responses always return 200 status codes.
if (payload.RootElement.TryGetProperty("error", out var error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

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

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

return (from address in payload.RootElement.GetProperty("values").EnumerateArray()
where address.GetProperty("is_primary").GetBoolean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement.GetProperty("data"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an OAuth token."));
}

using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
return OAuthTokenResponse.Success(payload);
}

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

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
6 changes: 2 additions & 4 deletions src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

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

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

return OAuthTokenResponse.Success(payload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
using var payload = await JsonDocument.ParseAsync(stream, cancellationToken: Context.RequestAborted);
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
var user = payload.RootElement
.GetProperty("d")
.GetProperty("results")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

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

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

return OAuthTokenResponse.Success(payload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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

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

0 comments on commit 4bee700

Please sign in to comment.