Skip to content

Commit

Permalink
Update to ASP.NET Core 8 preview 7
Browse files Browse the repository at this point in the history
- Update to preview 7 of ASP.NET Core 8.
- Suppress `CA1863` warnings to use `CompositeFormat`.
- Use `JsonDocument.ParseAsync()` where relevant.
  • Loading branch information
martincostello committed Aug 8, 2023
1 parent 61e4165 commit 1a20061
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<PackageVersion Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageVersion Include="JustEat.HttpClientInterception" Version="3.1.2" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0-preview.6.23329.11" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.0-preview.6.23329.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.0-preview.7.23375.9" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.16.0" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="Shouldly" Version="4.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-->
<PackageValidationBaselineVersion Condition="'$(PackageValidationBaselineVersion)' == ''">7.0.0</PackageValidationBaselineVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>6</PreReleaseVersionIteration>
<PreReleaseVersionIteration>7</PreReleaseVersionIteration>
<PreReleaseBrandingLabel>Preview $(PreReleaseVersionIteration)</PreReleaseBrandingLabel>
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"sdk": {
"version": "8.0.100-preview.6.23330.14",
"version": "8.0.100-preview.7.23376.3",
"allowPrerelease": true,
"rollForward": "major"
},

"tools": {
"dotnet": "8.0.100-preview.6.23330.14"
"dotnet": "8.0.100-preview.7.23376.3"
},

"msbuild-sdks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
}

using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
using var document = JsonDocument.Parse(stream);
using var document = await JsonDocument.ParseAsync(stream);

var mainElement = document.RootElement.GetProperty("alipay_system_oauth_token_response");
if (!ValidateReturnCode(mainElement, out var code))
Expand Down Expand Up @@ -120,7 +120,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
}

using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
using var document = JsonDocument.Parse(stream);
using var document = await JsonDocument.ParseAsync(stream);
var rootElement = document.RootElement;

if (!rootElement.TryGetProperty("alipay_user_info_share_response", out JsonElement mainElement))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public AmoCrmAuthenticationOptions()
ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
}

#pragma warning disable CA1863
/// <summary>
/// Gets or sets the amoCRM account name.
/// </summary>
Expand All @@ -48,4 +49,5 @@ public string Account
UserInformationEndpoint = string.Format(CultureInfo.InvariantCulture, AmoCrmAuthenticationDefaults.UserInformationEndpointFormat, value);
}
}
#pragma warning restore CA1863
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static class OktaAuthenticationDefaults
/// </summary>
public static readonly string UserInformationEndpointPathFormat = "/oauth2/{0}/v1/userinfo";

#pragma warning disable CA1863
/// <summary>
/// Default path to use for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
/// </summary>
Expand All @@ -67,4 +68,5 @@ public static class OktaAuthenticationDefaults
/// Default path to use for <see cref="OAuthOptions.UserInformationEndpoint"/>.
/// </summary>
public static readonly string UserInformationEndpointPath = string.Format(CultureInfo.InvariantCulture, UserInformationEndpointPathFormat, DefaultAuthorizationServer);
#pragma warning disable CA1863
}
6 changes: 3 additions & 3 deletions src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
}

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

var status = payload.RootElement.GetProperty("ret").GetInt32();

Expand Down Expand Up @@ -109,7 +109,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
}

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

return OAuthTokenResponse.Success(payload);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
}

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

var payloadRoot = payload.RootElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
#pragma warning disable CA1863
var uri = string.Format(
CultureInfo.InvariantCulture,
ShopifyAuthenticationDefaults.UserInformationEndpointFormat,
properties.Items[ShopifyAuthenticationDefaults.ShopNameAuthenticationProperty]);
#pragma warning restore CA1863

using var request = new HttpRequestMessage(HttpMethod.Get, uri);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
// UserInfo endpoint must support multiple subdomains, i.e. sod, sod1, online, online1, online2, ...
// - subdomain only becomes known from id token
// Example WebApi Url https://sod.superoffice.com/Cust12345/api/
#pragma warning disable CA1863
var userInfoEndpoint = string.Format(CultureInfo.InvariantCulture, SuperOfficeAuthenticationConstants.FormatStrings.UserInfoEndpoint, webApiUrl);
#pragma warning restore CA1863

// Get the SuperOffice user principal.
using var request = new HttpRequestMessage(HttpMethod.Get, userInfoEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private void UpdateEndpoints()
{
string env = GetEnvironment();

#pragma warning disable CA1863
AuthorizationEndpoint = string.Format(CultureInfo.InvariantCulture,
FormatStrings.AuthorizeEndpoint,
env);
Expand All @@ -167,5 +168,6 @@ private void UpdateEndpoints()
Authority = string.Format(CultureInfo.InvariantCulture,
FormatStrings.Authority,
env);
#pragma warning restore CA1863
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CA1054;CA1055;CA1707;CA1861;CA2227;CA5404</NoWarn>
<NoWarn>$(NoWarn);CA1054;CA1055;CA1707;CA1861;CA1863;CA2227;CA5404</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void Publicly_Visible_Parameters_Have_Null_Annotations()
testedMethods.ShouldBeGreaterThan(0);
}

private static IList<AssemblyName> GetProviderAssemblyNames()
private static AssemblyName[] GetProviderAssemblyNames()
{
var thisType = typeof(StaticAnalysisTests);

Expand All @@ -72,7 +72,7 @@ private static IList<AssemblyName> GetProviderAssemblyNames()
return assemblies;
}

private static IList<Type> GetPublicTypes(IEnumerable<AssemblyName> assemblyNames)
private static Type[] GetPublicTypes(IEnumerable<AssemblyName> assemblyNames)
{
var types = assemblyNames
.Select((p) => AssemblyLoadContext.Default.LoadFromAssemblyName(p))
Expand All @@ -85,7 +85,7 @@ private static IList<Type> GetPublicTypes(IEnumerable<AssemblyName> assemblyName
return types;
}

private static IList<MethodBase> GetPublicOrProtectedConstructorsOrMethods(Type type)
private static MethodBase[] GetPublicOrProtectedConstructorsOrMethods(Type type)
{
var constructors = type
.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic)
Expand Down

0 comments on commit 1a20061

Please sign in to comment.