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

Commit 2a4a7dd

Browse files
authored
Make samples work. Fix AddOAuthAuthentication extension. (#1226)
1 parent 1f5a27e commit 2a4a7dd

File tree

9 files changed

+55
-26
lines changed

9 files changed

+55
-26
lines changed

samples/CookieSample/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public class Startup
1313
{
1414
public void ConfigureServices(IServiceCollection services)
1515
{
16+
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
17+
services.AddAuthentication(options =>
18+
{
19+
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
20+
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
21+
});
22+
1623
services.AddCookieAuthentication();
1724
}
1825

samples/CookieSessionSample/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public class Startup
1414
{
1515
public void ConfigureServices(IServiceCollection services)
1616
{
17+
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
18+
services.AddAuthentication(options =>
19+
{
20+
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
21+
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
22+
});
23+
1724
services.AddCookieAuthentication(o => o.SessionStore = new MemoryCacheTicketStore());
1825
}
1926

samples/JwtBearerSample/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public Startup(IHostingEnvironment env)
4343
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
4444
public void ConfigureServices(IServiceCollection services)
4545
{
46+
// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
47+
services.AddAuthentication(options =>
48+
{
49+
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
50+
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
51+
});
52+
4653
services.AddJwtBearerAuthentication(o =>
4754
{
4855
// You also need to update /wwwroot/app/scripts/app.js

samples/OpenIdConnectSample/OpenIdConnectSample.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

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

@@ -7,6 +7,10 @@
77
<UserSecretsId>aspnet5-OpenIdConnectSample-20151210110318</UserSecretsId>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<None Remove="compiler\resources\cert.pfx" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
1216
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.OpenIdConnect\Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj" />
@@ -25,4 +29,8 @@
2529
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="$(AspNetCoreVersion)" />
2630
</ItemGroup>
2731

32+
<ItemGroup>
33+
<EmbeddedResource Include="compiler\resources\cert.pfx" />
34+
</ItemGroup>
35+
2836
</Project>

samples/OpenIdConnectSample/Program.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ public static void Main(string[] args)
2323
})
2424
.UseKestrel(options =>
2525
{
26-
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
26+
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
2727
{
28-
// ANCM is not hosting the process
29-
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
30-
{
31-
// Configure SSL
32-
var serverCertificate = LoadCertificate();
33-
listenOptions.UseHttps(serverCertificate);
34-
});
35-
}
28+
// Configure SSL
29+
var serverCertificate = LoadCertificate();
30+
listenOptions.UseHttps(serverCertificate);
31+
});
3632
})
3733
.UseContentRoot(Directory.GetCurrentDirectory())
3834
.UseIISIntegration()

samples/SocialSample/Program.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@ public static void Main(string[] args)
2121
})
2222
.UseKestrel(options =>
2323
{
24-
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNETCORE_PORT")))
24+
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
2525
{
26-
// ANCM is not hosting the process
27-
options.Listen(IPAddress.Loopback, 44318, listenOptions =>
28-
{
29-
// Configure SSL
30-
var serverCertificate = LoadCertificate();
31-
listenOptions.UseHttps(serverCertificate);
32-
});
33-
}
26+
// Configure SSL
27+
var serverCertificate = LoadCertificate();
28+
listenOptions.UseHttps(serverCertificate);
29+
});
3430
})
3531
.UseContentRoot(Directory.GetCurrentDirectory())
3632
.UseIISIntegration()

samples/SocialSample/SocialSample.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

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

@@ -7,6 +7,14 @@
77
<UserSecretsId>aspnet5-SocialSample-20151210111056</UserSecretsId>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<None Remove="compiler\resources\cert.pfx" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<EmbeddedResource Include="compiler\resources\cert.pfx" />
16+
</ItemGroup>
17+
1018
<ItemGroup>
1119
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Cookies\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
1220
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.Facebook\Microsoft.AspNetCore.Authentication.Facebook.csproj" />

samples/SocialSample/Startup.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ public void ConfigureServices(IServiceCollection services)
164164
o.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
165165
o.TokenEndpoint = "https://github.com/login/oauth/access_token";
166166
o.SaveTokens = true;
167-
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
168-
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
169-
o.ClaimActions.MapJsonKey("urn:github:name", "name");
170-
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
171-
o.ClaimActions.MapJsonKey("urn:github:url", "url");
172167
});
173168

174169
// You must first create an app with GitHub and add its ID and Secret to your user-secrets.
@@ -184,6 +179,11 @@ public void ConfigureServices(IServiceCollection services)
184179
o.ClaimsIssuer = "OAuth2-Github";
185180
o.SaveTokens = true;
186181
// Retrieving user information is unique to each provider.
182+
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
183+
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
184+
o.ClaimActions.MapJsonKey("urn:github:name", "name");
185+
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
186+
o.ClaimActions.MapJsonKey("urn:github:url", "url");
187187
o.Events = new OAuthEvents
188188
{
189189
OnCreatingTicket = async context =>

src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class OAuthExtensions
1212
{
1313
public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action<OAuthOptions> configureOptions)
1414
{
15-
return services.AddScheme<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, authenticationScheme, configureOptions);
15+
return services.AddOAuthAuthentication<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, configureOptions);
1616
}
1717

1818
public static IServiceCollection AddOAuthAuthentication<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<TOptions> configureOptions)

0 commit comments

Comments
 (0)