From 7d6349c81d6c9b49ea93bdef7ea6220f9e5ddeb6 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 20 Apr 2015 15:55:46 -0700 Subject: [PATCH] Fix samples. --- .../Properties/launchSettings.json | 21 +++++++++++++++++++ samples/CookieSample/Startup.cs | 10 ++++++--- samples/CookieSample/project.json | 1 + .../Properties/launchSettings.json | 21 +++++++++++++++++++ samples/CookieSessionSample/Startup.cs | 12 +++++++---- samples/CookieSessionSample/project.json | 5 +++-- .../Properties/launchSettings.json | 21 +++++++++++++++++++ samples/OpenIdConnectSample/Startup.cs | 7 +++++-- samples/OpenIdConnectSample/project.json | 9 ++++---- .../Properties/launchSettings.json | 21 +++++++++++++++++++ samples/SocialSample/SocialSample.xproj | 2 +- samples/SocialSample/Startup.cs | 14 ++++++++----- samples/SocialSample/project.json | 3 ++- 13 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 samples/CookieSample/Properties/launchSettings.json create mode 100644 samples/CookieSessionSample/Properties/launchSettings.json create mode 100644 samples/OpenIdConnectSample/Properties/launchSettings.json create mode 100644 samples/SocialSample/Properties/launchSettings.json diff --git a/samples/CookieSample/Properties/launchSettings.json b/samples/CookieSample/Properties/launchSettings.json new file mode 100644 index 0000000000..381ef9b50e --- /dev/null +++ b/samples/CookieSample/Properties/launchSettings.json @@ -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" + } + } +} \ No newline at end of file diff --git a/samples/CookieSample/Startup.cs b/samples/CookieSample/Startup.cs index e700f4b90a..cff155a787 100644 --- a/samples/CookieSample/Startup.cs +++ b/samples/CookieSample/Startup.cs @@ -1,8 +1,9 @@ using System.Security.Claims; +using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Authentication.Cookies; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; namespace CookieSample { @@ -14,8 +15,10 @@ namespace CookieSample services.AddDataProtection(); } - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) { + loggerfactory.AddConsole(LogLevel.Information); + app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; @@ -25,7 +28,8 @@ namespace CookieSample { 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"; await context.Response.WriteAsync("Hello First timer"); return; diff --git a/samples/CookieSample/project.json b/samples/CookieSample/project.json index eea2a4c7e3..1c559aeba3 100644 --- a/samples/CookieSample/project.json +++ b/samples/CookieSample/project.json @@ -3,6 +3,7 @@ "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*", + "Microsoft.Framework.Logging.Console": "1.0.0-*", "Kestrel": "1.0.0-*" }, "commands": { diff --git a/samples/CookieSessionSample/Properties/launchSettings.json b/samples/CookieSessionSample/Properties/launchSettings.json new file mode 100644 index 0000000000..381ef9b50e --- /dev/null +++ b/samples/CookieSessionSample/Properties/launchSettings.json @@ -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" + } + } +} \ No newline at end of file diff --git a/samples/CookieSessionSample/Startup.cs b/samples/CookieSessionSample/Startup.cs index decbd181a3..314ff37825 100644 --- a/samples/CookieSessionSample/Startup.cs +++ b/samples/CookieSessionSample/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Authentication.Cookies; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; namespace CookieSessionSample { @@ -15,20 +16,23 @@ namespace CookieSessionSample 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(); }); app.Run(async context => { - if (context.User.Identity == null || !context.User.Identity.IsAuthenticated) + if (string.IsNullOrEmpty(context.User.Identity.Name)) { // Make a large identity var claims = new List(1001); - claims.Add(new Claim("name", "bob")); + claims.Add(new Claim(ClaimTypes.Name, "bob")); for (int i = 0; i < 1000; i++) { claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe")); diff --git a/samples/CookieSessionSample/project.json b/samples/CookieSessionSample/project.json index 253079cebb..0e8c9a350e 100644 --- a/samples/CookieSessionSample/project.json +++ b/samples/CookieSessionSample/project.json @@ -1,10 +1,11 @@ { "dependencies": { "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", + "Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.Framework.Caching.Memory": "1.0.0-*", - "Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*" + "Microsoft.Framework.Logging.Console": "1.0.0-*", + "Kestrel": "1.0.0-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345", diff --git a/samples/OpenIdConnectSample/Properties/launchSettings.json b/samples/OpenIdConnectSample/Properties/launchSettings.json new file mode 100644 index 0000000000..d8622657cf --- /dev/null +++ b/samples/OpenIdConnectSample/Properties/launchSettings.json @@ -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" + } + } +} \ No newline at end of file diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index c93eae671b..29b89c8240 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; 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 => { options.AutomaticAuthentication = true; @@ -36,7 +39,7 @@ namespace OpenIdConnectSample 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); diff --git a/samples/OpenIdConnectSample/project.json b/samples/OpenIdConnectSample/project.json index e6e8d6a7b6..13d492ed37 100644 --- a/samples/OpenIdConnectSample/project.json +++ b/samples/OpenIdConnectSample/project.json @@ -1,10 +1,11 @@ { "dependencies": { - "Kestrel": "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.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": { "dnx451": { }, @@ -13,6 +14,6 @@ "commands": { "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" - }, + }, "webroot": "wwwroot" } diff --git a/samples/SocialSample/Properties/launchSettings.json b/samples/SocialSample/Properties/launchSettings.json new file mode 100644 index 0000000000..88e42ba2bb --- /dev/null +++ b/samples/SocialSample/Properties/launchSettings.json @@ -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/" + } + } +} \ No newline at end of file diff --git a/samples/SocialSample/SocialSample.xproj b/samples/SocialSample/SocialSample.xproj index d12b8fcbfe..3d2aa528d0 100644 --- a/samples/SocialSample/SocialSample.xproj +++ b/samples/SocialSample/SocialSample.xproj @@ -12,7 +12,7 @@ 2.0 - 36504 + 54540 \ No newline at end of file diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index 45c775cd13..aea458e1ad 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -10,6 +10,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; 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.UseCookieAuthentication(options => - { - options.LoginPath = new PathString("/login"); - }); + { + options.AutomaticAuthentication = true; + options.LoginPath = new PathString("/login"); + }); // https://developers.facebook.com/apps/ app.UseFacebookAuthentication(options => @@ -217,7 +221,7 @@ namespace CookieSample // Deny anonymous request beyond this point. 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 context.Response.Challenge(); diff --git a/samples/SocialSample/project.json b/samples/SocialSample/project.json index 30905d0b39..7c52600f35 100644 --- a/samples/SocialSample/project.json +++ b/samples/SocialSample/project.json @@ -1,13 +1,14 @@ { "dependencies": { - "Microsoft.AspNet.Diagnostics": "1.0.0-*", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", "Microsoft.AspNet.Authentication.Google": "1.0.0-*", "Microsoft.AspNet.Authentication.MicrosoftAccount": "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.WebListener": "1.0.0-*", + "Microsoft.Framework.Logging.Console": "1.0.0-*", "Kestrel": "1.0.0-*" }, "commands": {