Skip to content

Commit 2cd3c25

Browse files
Update to .NET 6 (#623)
* Update to .NET 6 Update the providers to .NET 6, using new language features and APIs as appropriate. * Require VS 2022 Update the solution file to require Visual Studio 2022. * Fix pre-release label Use "preview" not "rc.2". * Update Arcade Update Arcade to the same version as used to build the v6.0.0 tag for dotnet/aspnetcore. * Remove custom NuGet feeds Remove custom NuGet feeds to packages for .NET 6 are sourced from NuGet.org.
1 parent 8b7e4d4 commit 2cd3c25

File tree

534 files changed

+4391
-5052
lines changed

Some content is hidden

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

534 files changed

+4391
-5052
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Checkout code
3131
uses: actions/checkout@v2
3232

33-
- name: Setup .NET Core SDK
33+
- name: Setup .NET SDK
3434
uses: actions/setup-dotnet@v1
3535

3636
# Arcade only allows the revision to contain up to two characters, and GitHub Actions does not roll-over

AspNet.Security.OAuth.Providers.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28803.156
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31825.309
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}"
77
EndProject

Directory.Build.props

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
44

55
<PropertyGroup>
6-
<DefaultNetCoreTargetFramework>net5.0</DefaultNetCoreTargetFramework>
6+
<DefaultNetCoreTargetFramework>net6.0</DefaultNetCoreTargetFramework>
77
<LangVersion>latest</LangVersion>
88
<NoWarn>$(NoWarn);CS1591</NoWarn>
9+
<!-- TODO Actually resolve this by using the logging source generator -->
10+
<NoWarn>$(NoWarn);CA1848</NoWarn>
911
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1012
<DebugSymbols>true</DebugSymbols>
1113
<DebugType>portable</DebugType>
@@ -63,6 +65,12 @@
6365
<EnableNETAnalyzers>true</EnableNETAnalyzers>
6466
</PropertyGroup>
6567

68+
<PropertyGroup>
69+
<EnablePackageValidation>$(IsPackable)</EnablePackageValidation>
70+
<!-- TODO Remove suppression once 6.0.0 is released. -->
71+
<NoWarn>$(NoWarn);PKV006</NoWarn>
72+
</PropertyGroup>
73+
6674
<ItemGroup>
6775
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
6876
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
@@ -73,4 +81,14 @@
7381
<ProjectCapability Include="DynamicFileNesting" />
7482
</ItemGroup>
7583

84+
<PropertyGroup>
85+
<ImplicitUsings>enable</ImplicitUsings>
86+
</PropertyGroup>
87+
88+
<ItemGroup>
89+
<Using Include="JetBrains.Annotations" />
90+
<Using Include="Microsoft.AspNetCore.Authentication" />
91+
<Using Include="Microsoft.AspNetCore.Authentication.OAuth" />
92+
</ItemGroup>
93+
7694
</Project>

NuGet.config

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
4+
<clear />
45
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
56
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
67
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
7-
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
8-
<add key="azureadwebstacknightly" value="https://www.myget.org/F/azureadwebstacknightly/api/v3/index.json" />
8+
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
99
</packageSources>
10+
<disabledPackageSources>
11+
<clear />
12+
</disabledPackageSources>
1013
</configuration>

Packages.props

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<Project>
22

33
<ItemGroup>
4-
<PackageReference Update="JetBrains.Annotations" Version="2021.1.0" />
5-
<PackageReference Update="JustEat.HttpClientInterception" Version="3.1.0" />
6-
<PackageReference Update="MartinCostello.Logging.XUnit" Version="0.1.1" />
7-
<PackageReference Update="Microsoft.AspNetCore.Authentication.Google" Version="5.0.6" />
8-
<PackageReference Update="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.6" />
9-
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.6" />
10-
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="5.0.6" />
11-
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.6.0" />
4+
<PackageReference Update="JetBrains.Annotations" Version="2021.3.0" />
5+
<PackageReference Update="JustEat.HttpClientInterception" Version="3.1.1" />
6+
<PackageReference Update="MartinCostello.Logging.XUnit" Version="0.2.0" />
7+
<PackageReference Update="Microsoft.AspNetCore.Authentication.Google" Version="6.0.0" />
8+
<PackageReference Update="Microsoft.AspNetCore.Authentication.Twitter" Version="6.0.0" />
9+
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
10+
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
11+
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.10.0" />
1212
<PackageReference Update="Moq" Version="4.16.1" />
1313
<PackageReference Update="Shouldly" Version="4.0.3" />
14-
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118" />
15-
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
14+
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.354" />
1615
</ItemGroup>
1716

1817
</Project>

docs/discord.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ _None._
1919

2020
| Property Name | Property Type | Description | Default Value |
2121
|:--|:--|:--|:--|
22-
| `DiscordAvatarFormat` | `string` | Gets or sets the URL format string to use for user avatar images. | `DiscordAuthenticationConstants.Urls.AvatarUrlFormat` |
23-
| `DiscordCdn` | `string` | The URL to use for the Discord CDN. | `DiscordAuthenticationConstants.Urls.DiscordCdn` |
2422
| `Prompt` | `string?` | The value to use for the `prompt` query string parameter when making HTTP requests to the authorization endpoint. | `null` |
23+
24+
## Avatars as Claims
25+
26+
Versions of the Discord provider before version `6.0.0` would automatically map the user's avatar URL as the `urn:discord:avatar:url` claim.
27+
28+
This functionality is no longer built-in (see [#584](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/issues/584) and [#585](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/pull/585)), but can be added to your application with some extra code similar to that shown in the sample below.
29+
30+
```csharp
31+
services.AddAuthentication(options => /* Auth configuration */)
32+
.AddDiscord(options =>
33+
{
34+
options.ClientId = "my-client-id";
35+
options.ClientSecret = "my-client-secret";
36+
37+
options.ClaimActions.MapCustomJson("urn:discord:avatar:url", user =>
38+
string.Format(
39+
CultureInfo.InvariantCulture,
40+
"https://cdn.discordapp.com/avatars/{0}/{1}.{2}",
41+
user.GetString("id"),
42+
user.GetString("avatar"),
43+
user.GetString("avatar").StartsWith("a_") ? "gif" : "png"));
44+
});
45+
```

docs/sign-in-with-apple.md

+42-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This document provides some additional information and context to help you confi
1010

1111
Unlike other providers, the `ClientSecret` property is not used as _Sign in with Apple_ does not use a static client secret value. Instead the client secret has to be generated using a private key file provided by Apple from the Developer Portal that is used with the Key ID and Team ID to create a signed JSON Web Token (JWT).
1212

13-
The provider comes with a built-in extension method ([`UsePrivateKey(string)`](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/8e4c19008f518f3730bab90a980e01347ba6f3d3/src/AspNet.Security.OAuth.Apple/AppleAuthenticationOptionsExtensions.cs#L20-L33 "UsePrivateKey() extension method")) to generate they secret from a `.p8` certificate file on disk that you provide. Here's a [code example](https://github.com/martincostello/SignInWithAppleSample/blob/245bb70a164b66ec98ea3c2040a7387b0a3e8f0e/src/SignInWithApple/Startup.cs#L37-L46 "Example code to configure the Apple provider"):
13+
The provider comes with a built-in extension method `UsePrivateKey(string)` to generate they secret from a `.p8` certificate file on disk that you provide. Here's a code example:
1414

1515
```csharp
1616
services.AddAuthentication(options => /* Auth configuration */)
@@ -25,20 +25,49 @@ services.AddAuthentication(options => /* Auth configuration */)
2525
});
2626
```
2727

28-
Alternatively you can use the [`Func<string, Task<byte[]>> PrivateKeyBytes`](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/8e4c19008f518f3730bab90a980e01347ba6f3d3/src/AspNet.Security.OAuth.Apple/AppleAuthenticationOptions.cs#L78-L85 "Definition of PrivateKeyBytes property") property of the `AppleAuthenticationOptions` class to provide a delegate to a custom method of your own that loads the private key's bytes from another location, such as Azure Key Vault, Kubernetes secrets etc.
28+
Alternatively you can use the `Func<string, Task<ReadOnlyMemory<char>>> PrivateKey` property of the `AppleAuthenticationOptions` class to provide a delegate to a custom method of your own that loads the private key's bytes from another location, such as Azure Key Vault, Kubernetes secrets etc.
2929

30-
### Issues Loading Private Key
30+
Below are two examples of this approach.
31+
32+
#### Loading from an Environment Variable
3133

32-
If you encounter issues loading the private key of the certificate, the reasons could include one of the two scenarios:
34+
```csharp
35+
services.AddAuthentication(options => /* Auth configuration */)
36+
.AddApple(options =>
37+
{
38+
options.ClientId = Configuration["Apple:ClientId"];
39+
options.KeyId = Configuration["Apple:KeyId"];
40+
options.TeamId = Configuration["Apple:TeamId"];
41+
options.PrivateKey = (keyId, _) =>
42+
{
43+
return Task.FromResult(Configuration[$"Apple:Key:{keyId}"].AsMemory());
44+
};
45+
});
46+
```
3347

34-
1. Using .NET Core 2.x on Linux or macOS
35-
1. Using Windows Server with IIS
48+
#### Loading from Azure Key Vault
3649

37-
#### .NET Core 2.x on Linux or macOS
50+
```csharp
51+
services.AddAuthentication(options => /* Auth configuration */)
52+
.AddApple()
53+
.Services
54+
.AddOptions<AppleAuthenticationOptions>(AppleAuthenticationDefaults.AuthenticationScheme)
55+
.Configure<IConfiguration, SecretClient>((options, configuration, client) =>
56+
{
57+
options.ClientId = configuration["Apple:ClientId"];
58+
options.KeyId = configuration["Apple:KeyId"];
59+
options.TeamId = configuration["Apple:TeamId"];
60+
options.PrivateKey = async (keyId, cancellationToken) =>
61+
{
62+
var secret = await client.GetSecretAsync($"AuthKey-{keyId}", cancellationToken: cancellationToken);
63+
return secret.Value.Value.AsMemory();
64+
};
65+
});
66+
```
3867

39-
For the first scenario, before .NET Core 3.0 non-Windows platforms did not support loading `.p8` (PKCS #8) files. If you cannot use .NET Core 3.1 or later, it is recommended that you create a `.pfx` certificate file from your `.p8` file and use that instead.
68+
### Issues Loading Private Key
4069

41-
Further information can be found in this GitHub issue: https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/issues/390
70+
If you encounter issues loading the private key of the certificate, the reasons could include one of the following scenarios.
4271

4372
#### Windows Server with IIS
4473

@@ -63,7 +92,7 @@ Below are links to some issues raised against this repository that were related
6392

6493
## Sign in with Apple on iOS
6594

66-
When using _Sign In with Apple_ on an iOS 13+ Device, [Apple provides a different authentication workflow](https://developer.apple.com/documentation/authenticationservices) that returns the validation response to the app instead of in a server callback. Using that response to authenticate a user against your own backend requires sending the response to your servers and [communicating with the Apple authentication endpoint from there](https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens).
95+
When using _Sign In with Apple_ on an iOS 13+ Device, [Apple provides a different authentication workflow](https://developer.apple.com/documentation/authenticationservices) that returns the validation response to the app instead of in a server callback. Using that response to authenticate a user against your own backend requires sending the response to your servers and [communicating with the Apple authentication endpoint from there](https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens).
6796

6897
This workflow is out of the scope of this package but client secret generation and token validation can provide a starting point for an ASP.NET.Core integration. Note that the `ClientId` in this case is the App Id where the authentication was requested, not your Services Id.
6998

@@ -84,14 +113,12 @@ Below are links to a number of other documentation sources, blog posts and sampl
84113
|:--|:--|:--|:--|
85114
| `ClientSecretExpiresAfter` | `TimeSpan` | The period of time after which generated client secrets expire if `GenerateClientSecret` is set to `true`. | 6 months |
86115
| `ClientSecretGenerator` | `AppleClientSecretGenerator` | A service that generates client secrets for Sign In with Apple. | _An internal implementation_ |
116+
| `ConfigurationManager` | `IConfigurationManager<OpenIdConnectConfiguration>?` | The configuration manager to use for the OpenID configuration. | `null` |
87117
| `GenerateClientSecret` | `bool` | Whether to automatically generate a client secret. | `false` |
88-
| `JwtSecurityTokenHandler` | `JwtSecurityTokenHandler` | The handler to use to validate JSON Web Keys. | `new JwtSecurityTokenHandler()` |
89118
| `KeyId` | `string?` | The optional ID for your Sign in with Apple private key. | `null` |
90-
| `KeyStore` | `AppleKeyStore` | A service that loads private keys to use with Sign In with Apple. | _An internal implementation_ |
91-
| `PublicKeyCacheLifetime` | `TimeSpan` | The default period of time to cache Apple public key(s) for. | `TimeSpan.FromMinutes(15)` |
92-
| `PublicKeyEndpoint` | `string` | The URI to use to retrieve the Apple public keys. | `AppleAuthenticationDefaults.PublicKeyEndpoint` |
93-
| `PrivateKeyBytes` | `Func<string, Task<byte[]>>?` | An optional delegate to use to get the raw bytes of the client's private key in PKCS #8 format. | `null` |
119+
| `PrivateKeyBytes` | `Func<string, Task<ReadOnlyMemory<char>>>?` | An optional delegate to use to get the characters of the client's private key in PKCS #8 format. | `null` |
94120
| `TeamId` | `string` | The Team ID for your Apple Developer account. | `""` |
95121
| `TokenAudience` | `string` | The audience used for tokens. | `AppleAuthenticationConstants.Audience` |
96122
| `TokenValidator` | `AppleIdTokenValidator` | A service that validates Apple ID tokens. | `An internal implementation` |
123+
| `TokenValidationParameters` | `TokenValidationParameters` | The JSON Web Token validation parameters to use. | `new TokenValidationParameters()` |
97124
| `ValidateTokens` | `bool` | Whether to validate tokens using Apple's public key. | `true` |

eng/Version.Details.xml

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
</ProductDependencies>
66

77
<ToolsetDependencies>
8-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="5.0.0-beta.20180.5">
8+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="6.0.0-beta.21519.3">
99
<Uri>https://github.com/dotnet/arcade</Uri>
10-
<Sha>09bb9d929120b402348c9a0e9c8c951e824059aa</Sha>
10+
<Sha>85f3aa16d8797b5020f1fda11df1a958feb5f8df</Sha>
11+
<SourceBuild RepoName="arcade" ManagedOnly="true" />
1112
</Dependency>
1213

13-
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="5.0.0-beta.20180.5">
14+
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="6.0.0-beta.21519.3">
1415
<Uri>https://github.com/dotnet/arcade</Uri>
15-
<Sha>09bb9d929120b402348c9a0e9c8c951e824059aa</Sha>
16+
<Sha>85f3aa16d8797b5020f1fda11df1a958feb5f8df</Sha>
1617
</Dependency>
1718
</ToolsetDependencies>
1819

eng/Versions.props

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<Project>
22

33
<PropertyGroup>
4-
<MajorVersion>5</MajorVersion>
4+
<MajorVersion>6</MajorVersion>
55
<MinorVersion>0</MinorVersion>
6-
<PatchVersion>19</PatchVersion>
6+
<PatchVersion>0</PatchVersion>
77
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
8+
<!-- TODO Baseline to 6.0.0 once released -->
9+
<PackageValidationBaselineVersion>5.0.17</PackageValidationBaselineVersion>
810
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
911
<PreReleaseVersionIteration></PreReleaseVersionIteration>
1012
<PreReleaseBrandingLabel>Preview $(PreReleaseVersionIteration)</PreReleaseBrandingLabel>

0 commit comments

Comments
 (0)