Skip to content

Support ASP.NET 5 using RC1 #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<PackageVersion Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageVersion Include="JustEat.HttpClientInterception" Version="3.0.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Twitter" Version="3.1.7" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.7" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="3.1.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.0-rc.1.*" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.0-rc.1.*" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.0-rc.1.*" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="5.0.0-rc.1.*" />
<PackageVersion Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.5.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.6.0" />
<PackageVersion Include="Moq" Version="4.14.5" />
<PackageVersion Include="Shouldly" Version="3.0.2" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
</ItemGroup>

</Project>
12 changes: 8 additions & 4 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<Project>

<PropertyGroup>
<MajorVersion>3</MajorVersion>
<MinorVersion>1</MinorVersion>
<PatchVersion>4</PatchVersion>
<MajorVersion>5</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>0</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionLabel>rc</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<PreReleaseBrandingLabel>RC $(PreReleaseVersionIteration)</PreReleaseBrandingLabel>
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
<IncludePreReleaseLabelInPackageVersion>true</IncludePreReleaseLabelInPackageVersion>
<IncludePreReleaseLabelInPackageVersion Condition=" '$(DotNetFinalVersionKind)' == 'release' ">false</IncludePreReleaseLabelInPackageVersion>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tools": {
"dotnet": "3.1.401"
"dotnet": "5.0.100-rc.1.20452.10"
},

"msbuild-sdks": {
Expand Down
2 changes: 1 addition & 1 deletion samples/Mvc.Client/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IActionResult> SignIn([FromForm] string provider)

[HttpGet("~/signout")]
[HttpPost("~/signout")]
public IActionResult SignOut()
public override SignOutResult SignOut()
{
// Instruct the cookies middleware to delete the local cookie created
// when the user agent is redirected from the external identity provider
Expand Down
2 changes: 1 addition & 1 deletion samples/Mvc.Client/Mvc.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<UserSecretsId>AspNet.Security.OAuth.Providers.Mvc.Client</UserSecretsId>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AppleAuthenticationEvents : OAuthEvents
/// </summary>
public Func<AppleGenerateClientSecretContext, Task> OnGenerateClientSecret { get; set; } = async context =>
{
var provider = context.HttpContext.RequestServices.GetService<AppleClientSecretGenerator>();
var provider = context.HttpContext!.RequestServices!.GetRequiredService<AppleClientSecretGenerator>();
context.Options.ClientSecret = await provider.GenerateAsync(context);
};

Expand Down
10 changes: 5 additions & 5 deletions src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
string idToken = tokens.Response.RootElement.GetString("id_token");
string? idToken = tokens.Response.RootElement.GetString("id_token");

Logger.LogInformation("Creating ticket for Sign in with Apple.");

Expand Down Expand Up @@ -118,7 +118,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}

/// <inheritdoc />
Expand Down Expand Up @@ -170,13 +170,13 @@ protected virtual IEnumerable<Claim> ExtractClaimsFromUser([NotNull] JsonElement

if (user.TryGetProperty("name", out var name))
{
claims.Add(new Claim(ClaimTypes.GivenName, name.GetString("firstName"), ClaimValueTypes.String, ClaimsIssuer));
claims.Add(new Claim(ClaimTypes.Surname, name.GetString("lastName"), ClaimValueTypes.String, ClaimsIssuer));
claims.Add(new Claim(ClaimTypes.GivenName, name.GetString("firstName") ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
claims.Add(new Claim(ClaimTypes.Surname, name.GetString("lastName") ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
}

if (user.TryGetProperty("email", out var email))
{
claims.Add(new Claim(ClaimTypes.Email, email.GetString(), ClaimValueTypes.String, ClaimsIssuer));
claims.Add(new Claim(ClaimTypes.Email, email.GetString() ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
}

return claims;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] OAuthTokenResponse tokens)
{
// Note: the ArcGIS API doesn't support content negotiation via headers.
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>
{
["f"] = "json",
["token"] = tokens.AccessToken
Expand Down Expand Up @@ -68,7 +68,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions(payload.RootElement.GetProperty("data"));

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}

protected override string BuildChallengeUrl([NotNull] AuthenticationProperties properties, [NotNull] string redirectUri)
{
// Note: the redirect_uri parameter is not allowed by Automatic and MUST NOT be sent.
return QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, new Dictionary<string, string>
return QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, new Dictionary<string, string?>
{
["client_id"] = Options.ClientId,
["response_type"] = "code",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BaiduAuthenticationOptions()
ClaimActions.MapCustomJson(BaiduAuthenticationConstants.Claims.Portrait,
user =>
{
string portrait = user.GetString("portrait");
string? portrait = user.GetString("portrait");
return string.IsNullOrWhiteSpace(portrait) ?
null :
$"https://tb.himg.baidu.com/sys/portrait/item/{WebUtility.UrlEncode(portrait)}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
Options.Scope.Contains("email"))
{
string address = await GetEmailAsync(tokens);
string? address = await GetEmailAsync(tokens);

if (!string.IsNullOrEmpty(address))
{
identity.AddClaim(new Claim(ClaimTypes.Email, address, ClaimValueTypes.String, Options.ClaimsIssuer));
identity.AddClaim(new Claim(ClaimTypes.Email, address!, ClaimValueTypes.String, Options.ClaimsIssuer));
}
}

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}

protected virtual async Task<string> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
protected virtual async Task<string?> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
{
using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserEmailsEndpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading