Fix samples.

This commit is contained in:
Chris Ross 2015-04-20 15:55:46 -07:00
parent 7bc6cab72e
commit 7d6349c81d
13 changed files with 125 additions and 22 deletions

View File

@ -0,0 +1,21 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNET_ENV": "Development"
}
},
"web": {
"commandName": "web",
"launchBrowser": true,
"launchUrl": "http://localhost:12345"
},
"kestrel": {
"commandName": "kestrel",
"launchBrowser": true,
"launchUrl": "http://localhost:5004"
}
}
}

View File

@ -1,8 +1,9 @@
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace CookieSample namespace CookieSample
{ {
@ -14,8 +15,10 @@ namespace CookieSample
services.AddDataProtection(); services.AddDataProtection();
} }
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{ {
loggerfactory.AddConsole(LogLevel.Information);
app.UseCookieAuthentication(options => app.UseCookieAuthentication(options =>
{ {
options.AutomaticAuthentication = true; options.AutomaticAuthentication = true;
@ -25,7 +28,8 @@ namespace CookieSample
{ {
if (string.IsNullOrEmpty(context.User.Identity.Name)) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }))); var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }));
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user);
context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer"); await context.Response.WriteAsync("Hello First timer");
return; return;

View File

@ -3,6 +3,7 @@
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Kestrel": "1.0.0-*" "Kestrel": "1.0.0-*"
}, },
"commands": { "commands": {

View File

@ -0,0 +1,21 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNET_ENV": "Development"
}
},
"web": {
"commandName": "web",
"launchBrowser": true,
"launchUrl": "http://localhost:12345"
},
"kestrel": {
"commandName": "kestrel",
"launchBrowser": true,
"launchUrl": "http://localhost:5004"
}
}
}

View File

@ -4,6 +4,7 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace CookieSessionSample namespace CookieSessionSample
{ {
@ -15,20 +16,23 @@ namespace CookieSessionSample
services.AddDataProtection(); services.AddDataProtection();
} }
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{ {
app.UseCookieAuthentication(options => loggerfactory.AddConsole(LogLevel.Information);
app.UseCookieAuthentication(options =>
{ {
options.AutomaticAuthentication = true;
options.SessionStore = new MemoryCacheSessionStore(); options.SessionStore = new MemoryCacheSessionStore();
}); });
app.Run(async context => app.Run(async context =>
{ {
if (context.User.Identity == null || !context.User.Identity.IsAuthenticated) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
// Make a large identity // Make a large identity
var claims = new List<Claim>(1001); var claims = new List<Claim>(1001);
claims.Add(new Claim("name", "bob")); claims.Add(new Claim(ClaimTypes.Name, "bob"));
for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
{ {
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe")); claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));

View File

@ -1,10 +1,11 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.Framework.Caching.Memory": "1.0.0-*", "Microsoft.Framework.Caching.Memory": "1.0.0-*",
"Kestrel": "1.0.0-*", "Microsoft.Framework.Logging.Console": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*" "Kestrel": "1.0.0-*"
}, },
"commands": { "commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345", "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345",

View File

@ -0,0 +1,21 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNET_ENV": "Development"
}
},
"kestrel": {
"commandName": "kestrel",
"launchBrowser": true,
"launchUrl": "http://localhost:5004"
},
"web": {
"commandName": "web",
"launchBrowser": true,
"launchUrl": "http://localhost:12345"
}
}
}

View File

@ -5,6 +5,7 @@ using Microsoft.AspNet.Authentication;
using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Authentication.OpenIdConnect;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace OpenIdConnectSample namespace OpenIdConnectSample
{ {
@ -20,8 +21,10 @@ namespace OpenIdConnectSample
}); });
} }
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{ {
loggerfactory.AddConsole(LogLevel.Information);
app.UseCookieAuthentication(options => app.UseCookieAuthentication(options =>
{ {
options.AutomaticAuthentication = true; options.AutomaticAuthentication = true;
@ -36,7 +39,7 @@ namespace OpenIdConnectSample
app.Run(async context => app.Run(async context =>
{ {
if (context.User == null || !context.User.Identity.IsAuthenticated) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme); context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme);

View File

@ -1,10 +1,11 @@
{ {
"dependencies": { "dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*", "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*" "Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Kestrel": "1.0.0-*"
}, },
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },
@ -13,6 +14,6 @@
"commands": { "commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345", "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004" "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
}, },
"webroot": "wwwroot" "webroot": "wwwroot"
} }

View File

@ -0,0 +1,21 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNET_ENV": "Development"
}
},
"kestrel": {
"commandName": "kestrel",
"launchBrowser": true,
"launchUrl": "http://localhost:54540/"
},
"web": {
"commandName": "web",
"launchBrowser": true,
"launchUrl": "http://localhost:54540/"
}
}
}

View File

@ -12,7 +12,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>36504</DevelopmentServerPort> <DevelopmentServerPort>54540</DevelopmentServerPort>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project> </Project>

View File

@ -10,6 +10,7 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Authentication;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace CookieSample namespace CookieSample
@ -33,14 +34,17 @@ namespace CookieSample
}); });
} }
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{ {
loggerfactory.AddConsole(LogLevel.Information);
app.UseErrorPage(); app.UseErrorPage();
app.UseCookieAuthentication(options => app.UseCookieAuthentication(options =>
{ {
options.LoginPath = new PathString("/login"); options.AutomaticAuthentication = true;
}); options.LoginPath = new PathString("/login");
});
// https://developers.facebook.com/apps/ // https://developers.facebook.com/apps/
app.UseFacebookAuthentication(options => app.UseFacebookAuthentication(options =>
@ -217,7 +221,7 @@ namespace CookieSample
// Deny anonymous request beyond this point. // Deny anonymous request beyond this point.
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {
if (!context.User.Identity.IsAuthenticated) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
// The cookie middleware will intercept this 401 and redirect to /login // The cookie middleware will intercept this 401 and redirect to /login
context.Response.Challenge(); context.Response.Challenge();

View File

@ -1,13 +1,14 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
"Microsoft.AspNet.Authentication.Google": "1.0.0-*", "Microsoft.AspNet.Authentication.Google": "1.0.0-*",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*", "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Kestrel": "1.0.0-*" "Kestrel": "1.0.0-*"
}, },
"commands": { "commands": {