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

Commit 7d6349c

Browse files
committed
Fix samples.
1 parent 7bc6cab commit 7d6349c

File tree

13 files changed

+125
-22
lines changed

13 files changed

+125
-22
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"profiles": {
3+
"IIS Express": {
4+
"commandName": "IISExpress",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNET_ENV": "Development"
8+
}
9+
},
10+
"web": {
11+
"commandName": "web",
12+
"launchBrowser": true,
13+
"launchUrl": "http://localhost:12345"
14+
},
15+
"kestrel": {
16+
"commandName": "kestrel",
17+
"launchBrowser": true,
18+
"launchUrl": "http://localhost:5004"
19+
}
20+
}
21+
}

samples/CookieSample/Startup.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Security.Claims;
2+
using Microsoft.AspNet.Authentication.Cookies;
23
using Microsoft.AspNet.Builder;
34
using Microsoft.AspNet.Http;
4-
using Microsoft.AspNet.Authentication.Cookies;
55
using Microsoft.Framework.DependencyInjection;
6+
using Microsoft.Framework.Logging;
67

78
namespace CookieSample
89
{
@@ -14,8 +15,10 @@ public void ConfigureServices(IServiceCollection services)
1415
services.AddDataProtection();
1516
}
1617

17-
public void Configure(IApplicationBuilder app)
18+
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
1819
{
20+
loggerfactory.AddConsole(LogLevel.Information);
21+
1922
app.UseCookieAuthentication(options =>
2023
{
2124
options.AutomaticAuthentication = true;
@@ -25,7 +28,8 @@ public void Configure(IApplicationBuilder app)
2528
{
2629
if (string.IsNullOrEmpty(context.User.Identity.Name))
2730
{
28-
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") })));
31+
var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }));
32+
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user);
2933
context.Response.ContentType = "text/plain";
3034
await context.Response.WriteAsync("Hello First timer");
3135
return;

samples/CookieSample/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
44
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
55
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
6+
"Microsoft.Framework.Logging.Console": "1.0.0-*",
67
"Kestrel": "1.0.0-*"
78
},
89
"commands": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"profiles": {
3+
"IIS Express": {
4+
"commandName": "IISExpress",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNET_ENV": "Development"
8+
}
9+
},
10+
"web": {
11+
"commandName": "web",
12+
"launchBrowser": true,
13+
"launchUrl": "http://localhost:12345"
14+
},
15+
"kestrel": {
16+
"commandName": "kestrel",
17+
"launchBrowser": true,
18+
"launchUrl": "http://localhost:5004"
19+
}
20+
}
21+
}

samples/CookieSessionSample/Startup.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNet.Http;
55
using Microsoft.AspNet.Authentication.Cookies;
66
using Microsoft.Framework.DependencyInjection;
7+
using Microsoft.Framework.Logging;
78

89
namespace CookieSessionSample
910
{
@@ -15,20 +16,23 @@ public void ConfigureServices(IServiceCollection services)
1516
services.AddDataProtection();
1617
}
1718

18-
public void Configure(IApplicationBuilder app)
19+
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
1920
{
20-
app.UseCookieAuthentication(options =>
21+
loggerfactory.AddConsole(LogLevel.Information);
22+
23+
app.UseCookieAuthentication(options =>
2124
{
25+
options.AutomaticAuthentication = true;
2226
options.SessionStore = new MemoryCacheSessionStore();
2327
});
2428

2529
app.Run(async context =>
2630
{
27-
if (context.User.Identity == null || !context.User.Identity.IsAuthenticated)
31+
if (string.IsNullOrEmpty(context.User.Identity.Name))
2832
{
2933
// Make a large identity
3034
var claims = new List<Claim>(1001);
31-
claims.Add(new Claim("name", "bob"));
35+
claims.Add(new Claim(ClaimTypes.Name, "bob"));
3236
for (int i = 0; i < 1000; i++)
3337
{
3438
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));

samples/CookieSessionSample/project.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"dependencies": {
33
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
4+
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
45
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
56
"Microsoft.Framework.Caching.Memory": "1.0.0-*",
6-
"Kestrel": "1.0.0-*",
7-
"Microsoft.AspNet.Server.IIS": "1.0.0-*"
7+
"Microsoft.Framework.Logging.Console": "1.0.0-*",
8+
"Kestrel": "1.0.0-*"
89
},
910
"commands": {
1011
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"profiles": {
3+
"IIS Express": {
4+
"commandName": "IISExpress",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNET_ENV": "Development"
8+
}
9+
},
10+
"kestrel": {
11+
"commandName": "kestrel",
12+
"launchBrowser": true,
13+
"launchUrl": "http://localhost:5004"
14+
},
15+
"web": {
16+
"commandName": "web",
17+
"launchBrowser": true,
18+
"launchUrl": "http://localhost:12345"
19+
}
20+
}
21+
}

samples/OpenIdConnectSample/Startup.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNet.Authentication.Cookies;
66
using Microsoft.AspNet.Authentication.OpenIdConnect;
77
using Microsoft.Framework.DependencyInjection;
8+
using Microsoft.Framework.Logging;
89

910
namespace OpenIdConnectSample
1011
{
@@ -20,8 +21,10 @@ public void ConfigureServices(IServiceCollection services)
2021
});
2122
}
2223

23-
public void Configure(IApplicationBuilder app)
24+
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
2425
{
26+
loggerfactory.AddConsole(LogLevel.Information);
27+
2528
app.UseCookieAuthentication(options =>
2629
{
2730
options.AutomaticAuthentication = true;
@@ -36,7 +39,7 @@ public void Configure(IApplicationBuilder app)
3639

3740
app.Run(async context =>
3841
{
39-
if (context.User == null || !context.User.Identity.IsAuthenticated)
42+
if (string.IsNullOrEmpty(context.User.Identity.Name))
4043
{
4144
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
4245

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"dependencies": {
3-
"Kestrel": "1.0.0-*",
43
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
5-
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
64
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
7-
"Microsoft.AspNet.Server.WebListener": "1.0.0-*"
5+
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
6+
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
7+
"Microsoft.Framework.Logging.Console": "1.0.0-*",
8+
"Kestrel": "1.0.0-*"
89
},
910
"frameworks": {
1011
"dnx451": { },
@@ -13,6 +14,6 @@
1314
"commands": {
1415
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345",
1516
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
16-
},
17+
},
1718
"webroot": "wwwroot"
1819
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"profiles": {
3+
"IIS Express": {
4+
"commandName": "IISExpress",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNET_ENV": "Development"
8+
}
9+
},
10+
"kestrel": {
11+
"commandName": "kestrel",
12+
"launchBrowser": true,
13+
"launchUrl": "http://localhost:54540/"
14+
},
15+
"web": {
16+
"commandName": "web",
17+
"launchBrowser": true,
18+
"launchUrl": "http://localhost:54540/"
19+
}
20+
}
21+
}

samples/SocialSample/SocialSample.xproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313
<PropertyGroup>
1414
<SchemaVersion>2.0</SchemaVersion>
15-
<DevelopmentServerPort>36504</DevelopmentServerPort>
15+
<DevelopmentServerPort>54540</DevelopmentServerPort>
1616
</PropertyGroup>
1717
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
1818
</Project>

samples/SocialSample/Startup.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.AspNet.Http;
1111
using Microsoft.AspNet.Http.Authentication;
1212
using Microsoft.Framework.DependencyInjection;
13+
using Microsoft.Framework.Logging;
1314
using Newtonsoft.Json.Linq;
1415

1516
namespace CookieSample
@@ -33,14 +34,17 @@ public void ConfigureServices(IServiceCollection services)
3334
});
3435
}
3536

36-
public void Configure(IApplicationBuilder app)
37+
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
3738
{
39+
loggerfactory.AddConsole(LogLevel.Information);
40+
3841
app.UseErrorPage();
3942

4043
app.UseCookieAuthentication(options =>
41-
{
42-
options.LoginPath = new PathString("/login");
43-
});
44+
{
45+
options.AutomaticAuthentication = true;
46+
options.LoginPath = new PathString("/login");
47+
});
4448

4549
// https://developers.facebook.com/apps/
4650
app.UseFacebookAuthentication(options =>
@@ -217,7 +221,7 @@ dnx . web
217221
// Deny anonymous request beyond this point.
218222
app.Use(async (context, next) =>
219223
{
220-
if (!context.User.Identity.IsAuthenticated)
224+
if (string.IsNullOrEmpty(context.User.Identity.Name))
221225
{
222226
// The cookie middleware will intercept this 401 and redirect to /login
223227
context.Response.Challenge();

samples/SocialSample/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"dependencies": {
3-
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
43
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
54
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
65
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
76
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
87
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
8+
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
99
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
1010
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
11+
"Microsoft.Framework.Logging.Console": "1.0.0-*",
1112
"Kestrel": "1.0.0-*"
1213
},
1314
"commands": {

0 commit comments

Comments
 (0)