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)
|
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();
|
services.AddCookieAuthentication();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,13 @@ namespace CookieSessionSample
|
||||||
{
|
{
|
||||||
public void ConfigureServices(IServiceCollection services)
|
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());
|
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
|
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
||||||
public void ConfigureServices(IServiceCollection services)
|
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 =>
|
services.AddJwtBearerAuthentication(o =>
|
||||||
{
|
{
|
||||||
// You also need to update /wwwroot/app/scripts/app.js
|
// 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" />
|
<Import Project="..\..\build\dependencies.props" />
|
||||||
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
<UserSecretsId>aspnet5-OpenIdConnectSample-20151210110318</UserSecretsId>
|
<UserSecretsId>aspnet5-OpenIdConnectSample-20151210110318</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="compiler\resources\cert.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.OpenIdConnect\Microsoft.AspNetCore.Authentication.OpenIdConnect.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)" />
|
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="$(AspNetCoreVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="compiler\resources\cert.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,12 @@ namespace OpenIdConnectSample
|
||||||
})
|
})
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
|
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||||
{
|
{
|
||||||
// ANCM is not hosting the process
|
// Configure SSL
|
||||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
var serverCertificate = LoadCertificate();
|
||||||
{
|
listenOptions.UseHttps(serverCertificate);
|
||||||
// Configure SSL
|
});
|
||||||
var serverCertificate = LoadCertificate();
|
|
||||||
listenOptions.UseHttps(serverCertificate);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseIISIntegration()
|
.UseIISIntegration()
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,12 @@ namespace SocialSample
|
||||||
})
|
})
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
|
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
||||||
{
|
{
|
||||||
// ANCM is not hosting the process
|
// Configure SSL
|
||||||
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
|
var serverCertificate = LoadCertificate();
|
||||||
{
|
listenOptions.UseHttps(serverCertificate);
|
||||||
// Configure SSL
|
});
|
||||||
var serverCertificate = LoadCertificate();
|
|
||||||
listenOptions.UseHttps(serverCertificate);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseIISIntegration()
|
.UseIISIntegration()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<Import Project="..\..\build\dependencies.props" />
|
<Import Project="..\..\build\dependencies.props" />
|
||||||
|
|
||||||
|
|
@ -7,6 +7,14 @@
|
||||||
<UserSecretsId>aspnet5-SocialSample-20151210111056</UserSecretsId>
|
<UserSecretsId>aspnet5-SocialSample-20151210111056</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="compiler\resources\cert.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="compiler\resources\cert.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Facebook\Microsoft.AspNetCore.Authentication.Facebook.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.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
|
||||||
o.TokenEndpoint = "https://github.com/login/oauth/access_token";
|
o.TokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||||
o.SaveTokens = true;
|
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.
|
// 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.ClaimsIssuer = "OAuth2-Github";
|
||||||
o.SaveTokens = true;
|
o.SaveTokens = true;
|
||||||
// Retrieving user information is unique to each provider.
|
// 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
|
o.Events = new OAuthEvents
|
||||||
{
|
{
|
||||||
OnCreatingTicket = async context =>
|
OnCreatingTicket = async context =>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action<OAuthOptions> configureOptions)
|
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)
|
public static IServiceCollection AddOAuthAuthentication<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<TOptions> configureOptions)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue