Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Make samples work. Fix AddOAuthAuthentication extension. #1226

Merged
merged 1 commit into from
May 22, 2017
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
7 changes: 7 additions & 0 deletions samples/CookieSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public class Startup
{
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();
}

Expand Down
7 changes: 7 additions & 0 deletions samples/CookieSessionSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class Startup
{
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());
}

Expand Down
7 changes: 7 additions & 0 deletions samples/JwtBearerSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public Startup(IHostingEnvironment env)
// 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
Expand Down
10 changes: 9 additions & 1 deletion samples/OpenIdConnectSample/OpenIdConnectSample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<Import Project="..\..\build\dependencies.props" />

Expand All @@ -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" />
Expand All @@ -25,4 +29,8 @@
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="$(AspNetCoreVersion)" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="compiler\resources\cert.pfx" />
</ItemGroup>

</Project>
14 changes: 5 additions & 9 deletions samples/OpenIdConnectSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ public static void Main(string[] args)
})
.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()
Expand Down
14 changes: 5 additions & 9 deletions samples/SocialSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ public static void Main(string[] args)
})
.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()
Expand Down
10 changes: 9 additions & 1 deletion samples/SocialSample/SocialSample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<Import Project="..\..\build\dependencies.props" />

Expand All @@ -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" />
Expand Down
10 changes: 5 additions & 5 deletions samples/SocialSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ public void ConfigureServices(IServiceCollection services)
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.
Expand All @@ -184,6 +179,11 @@ public void ConfigureServices(IServiceCollection services)
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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class OAuthExtensions
{
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)
Expand Down