Make samples work. Fix AddOAuthAuthentication extension. (#1226)
This commit is contained in:
parent
1f5a27e20a
commit
2a4a7dd26a
|
|
@ -13,6 +13,13 @@ namespace CookieSample
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
});
|
||||
|
||||
services.AddCookieAuthentication();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,13 @@ namespace CookieSessionSample
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
});
|
||||
|
||||
services.AddCookieAuthentication(o => o.SessionStore = new MemoryCacheTicketStore());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,13 @@ namespace JwtBearerSample
|
|||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
});
|
||||
|
||||
services.AddJwtBearerAuthentication(o =>
|
||||
{
|
||||
// You also need to update /wwwroot/app/scripts/app.js
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
|
|
@ -7,6 +7,10 @@
|
|||
<UserSecretsId>aspnet5-OpenIdConnectSample-20151210110318</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="compiler\resources\cert.pfx" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.OpenIdConnect\Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj" />
|
||||
|
|
@ -25,4 +29,8 @@
|
|||
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="compiler\resources\cert.pfx" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -23,16 +23,12 @@ namespace OpenIdConnectSample
|
|||
})
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
|
||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||
{
|
||||
// ANCM is not hosting the process
|
||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||
{
|
||||
// Configure SSL
|
||||
var serverCertificate = LoadCertificate();
|
||||
listenOptions.UseHttps(serverCertificate);
|
||||
});
|
||||
}
|
||||
// Configure SSL
|
||||
var serverCertificate = LoadCertificate();
|
||||
listenOptions.UseHttps(serverCertificate);
|
||||
});
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
|
|
|
|||
|
|
@ -21,16 +21,12 @@ namespace SocialSample
|
|||
})
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
|
||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||
{
|
||||
// ANCM is not hosting the process
|
||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||
{
|
||||
// Configure SSL
|
||||
var serverCertificate = LoadCertificate();
|
||||
listenOptions.UseHttps(serverCertificate);
|
||||
});
|
||||
}
|
||||
// Configure SSL
|
||||
var serverCertificate = LoadCertificate();
|
||||
listenOptions.UseHttps(serverCertificate);
|
||||
});
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
|
|
@ -7,6 +7,14 @@
|
|||
<UserSecretsId>aspnet5-SocialSample-20151210111056</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="compiler\resources\cert.pfx" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="compiler\resources\cert.pfx" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Facebook\Microsoft.AspNetCore.Authentication.Facebook.csproj" />
|
||||
|
|
|
|||
|
|
@ -164,11 +164,6 @@ namespace SocialSample
|
|||
o.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
|
||||
o.TokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||
o.SaveTokens = true;
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
|
||||
o.ClaimActions.MapJsonKey("urn:github:name", "name");
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
|
||||
o.ClaimActions.MapJsonKey("urn:github:url", "url");
|
||||
});
|
||||
|
||||
// You must first create an app with GitHub and add its ID and Secret to your user-secrets.
|
||||
|
|
@ -184,6 +179,11 @@ namespace SocialSample
|
|||
o.ClaimsIssuer = "OAuth2-Github";
|
||||
o.SaveTokens = true;
|
||||
// Retrieving user information is unique to each provider.
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
|
||||
o.ClaimActions.MapJsonKey("urn:github:name", "name");
|
||||
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
|
||||
o.ClaimActions.MapJsonKey("urn:github:url", "url");
|
||||
o.Events = new OAuthEvents
|
||||
{
|
||||
OnCreatingTicket = async context =>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action<OAuthOptions> configureOptions)
|
||||
{
|
||||
return services.AddScheme<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, authenticationScheme, configureOptions);
|
||||
return services.AddOAuthAuthentication<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, configureOptions);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddOAuthAuthentication<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<TOptions> configureOptions)
|
||||
|
|
|
|||
Loading…
Reference in New Issue