From 8b4b99b168c97b6c559ec0f971ae6389a669c153 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 17 May 2016 13:36:18 -0700 Subject: [PATCH] Clean up samples --- samples/CookieSample/Program.cs | 24 ++++++++ .../Properties/launchSettings.json | 9 +-- samples/CookieSample/Startup.cs | 11 ---- samples/CookieSample/project.json | 1 + samples/CookieSessionSample/Program.cs | 24 ++++++++ .../Properties/launchSettings.json | 9 +-- samples/CookieSessionSample/Startup.cs | 11 ---- samples/CookieSessionSample/project.json | 1 + samples/JwtBearerSample/Program.cs | 24 ++++++++ .../Properties/launchSettings.json | 9 ++- samples/JwtBearerSample/Startup.cs | 29 ++++------ .../OpenIdConnect.AzureAdSample/Program.cs | 24 ++++++++ .../Properties/launchSettings.json | 9 ++- .../OpenIdConnect.AzureAdSample/Startup.cs | 28 ++++----- samples/OpenIdConnectSample/Program.cs | 24 ++++++++ .../Properties/launchSettings.json | 8 +-- samples/OpenIdConnectSample/Startup.cs | 28 ++++----- samples/SocialSample/Program.cs | 50 ++++++++++++++++ .../Properties/launchSettings.json | 9 +-- samples/SocialSample/Startup.cs | 57 +++++-------------- .../{config.json => appsettings.json} | 0 samples/SocialSample/project.json | 4 +- 22 files changed, 254 insertions(+), 139 deletions(-) create mode 100644 samples/CookieSample/Program.cs create mode 100644 samples/CookieSessionSample/Program.cs create mode 100644 samples/JwtBearerSample/Program.cs create mode 100644 samples/OpenIdConnect.AzureAdSample/Program.cs create mode 100644 samples/OpenIdConnectSample/Program.cs create mode 100644 samples/SocialSample/Program.cs rename samples/SocialSample/{config.json => appsettings.json} (100%) diff --git a/samples/CookieSample/Program.cs b/samples/CookieSample/Program.cs new file mode 100644 index 0000000000..cd8aab3aee --- /dev/null +++ b/samples/CookieSample/Program.cs @@ -0,0 +1,24 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace CookieSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/samples/CookieSample/Properties/launchSettings.json b/samples/CookieSample/Properties/launchSettings.json index c85de8d26e..75da70bee0 100644 --- a/samples/CookieSample/Properties/launchSettings.json +++ b/samples/CookieSample/Properties/launchSettings.json @@ -12,15 +12,16 @@ "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { - "ASPNET_ENV": "Development" + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "CookieSample": { + "commandName": "Project", "launchBrowser": true, "launchUrl": "http://localhost:12345", "environmentVariables": { - "Hosting:Environment": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "http://localhost:12345" } } } diff --git a/samples/CookieSample/Startup.cs b/samples/CookieSample/Startup.cs index 768415f0ce..002d878885 100644 --- a/samples/CookieSample/Startup.cs +++ b/samples/CookieSample/Startup.cs @@ -41,16 +41,5 @@ namespace CookieSample await context.Response.WriteAsync("Hello old timer"); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/samples/CookieSample/project.json b/samples/CookieSample/project.json index c28a644d46..954c366434 100644 --- a/samples/CookieSample/project.json +++ b/samples/CookieSample/project.json @@ -5,6 +5,7 @@ "Microsoft.AspNetCore.DataProtection": "1.0.0-*", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "buildOptions": { diff --git a/samples/CookieSessionSample/Program.cs b/samples/CookieSessionSample/Program.cs new file mode 100644 index 0000000000..6b9014f5e9 --- /dev/null +++ b/samples/CookieSessionSample/Program.cs @@ -0,0 +1,24 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace CookieSessionSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/samples/CookieSessionSample/Properties/launchSettings.json b/samples/CookieSessionSample/Properties/launchSettings.json index 8d4a0316ab..15b478a0ed 100644 --- a/samples/CookieSessionSample/Properties/launchSettings.json +++ b/samples/CookieSessionSample/Properties/launchSettings.json @@ -12,15 +12,16 @@ "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { - "ASPNET_ENV": "Development" + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "CookieSessionSample": { + "commandName": "Project", "launchBrowser": true, "launchUrl": "http://localhost:12345", "environmentVariables": { - "Hosting:Environment": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "http://localhost:12345" } } } diff --git a/samples/CookieSessionSample/Startup.cs b/samples/CookieSessionSample/Startup.cs index 4d3ea3aa67..ecb61ab665 100644 --- a/samples/CookieSessionSample/Startup.cs +++ b/samples/CookieSessionSample/Startup.cs @@ -51,16 +51,5 @@ namespace CookieSessionSample await context.Response.WriteAsync("Hello old timer"); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/samples/CookieSessionSample/project.json b/samples/CookieSessionSample/project.json index d3caf9364f..a3626218c4 100644 --- a/samples/CookieSessionSample/project.json +++ b/samples/CookieSessionSample/project.json @@ -6,6 +6,7 @@ "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.Extensions.Caching.Memory": "1.0.0-*", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "buildOptions": { diff --git a/samples/JwtBearerSample/Program.cs b/samples/JwtBearerSample/Program.cs new file mode 100644 index 0000000000..82da93d591 --- /dev/null +++ b/samples/JwtBearerSample/Program.cs @@ -0,0 +1,24 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace JwtBearerSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/samples/JwtBearerSample/Properties/launchSettings.json b/samples/JwtBearerSample/Properties/launchSettings.json index 49cbac543a..f5dfcd0181 100644 --- a/samples/JwtBearerSample/Properties/launchSettings.json +++ b/samples/JwtBearerSample/Properties/launchSettings.json @@ -15,10 +15,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "JwtBearer": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "http://localhost:42023", "environmentVariables": { - "Hosting:Environment": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "http://localhost:42023" } } } diff --git a/samples/JwtBearerSample/Startup.cs b/samples/JwtBearerSample/Startup.cs index b2df5033e4..02611de8c4 100644 --- a/samples/JwtBearerSample/Startup.cs +++ b/samples/JwtBearerSample/Startup.cs @@ -13,12 +13,19 @@ namespace JwtBearerSample { public class Startup { - public Startup() + public Startup(IHostingEnvironment env) { - Configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .AddUserSecrets() - .Build(); + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath); + + if (env.IsDevelopment()) + { + // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } @@ -106,18 +113,6 @@ namespace JwtBearerSample }); }); } - - // Entry point for the application. - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/samples/OpenIdConnect.AzureAdSample/Program.cs b/samples/OpenIdConnect.AzureAdSample/Program.cs new file mode 100644 index 0000000000..5dcda4c86a --- /dev/null +++ b/samples/OpenIdConnect.AzureAdSample/Program.cs @@ -0,0 +1,24 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace OpenIdConnect.AzureAdSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/samples/OpenIdConnect.AzureAdSample/Properties/launchSettings.json b/samples/OpenIdConnect.AzureAdSample/Properties/launchSettings.json index 49cbac543a..2ae08a6cc9 100644 --- a/samples/OpenIdConnect.AzureAdSample/Properties/launchSettings.json +++ b/samples/OpenIdConnect.AzureAdSample/Properties/launchSettings.json @@ -15,10 +15,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "OpenIdConnect": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "http://localhost:42023", "environmentVariables": { - "Hosting:Environment": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "http://localhost:42023" } } } diff --git a/samples/OpenIdConnect.AzureAdSample/Startup.cs b/samples/OpenIdConnect.AzureAdSample/Startup.cs index 7d8cf23461..f4d0c37aaa 100644 --- a/samples/OpenIdConnect.AzureAdSample/Startup.cs +++ b/samples/OpenIdConnect.AzureAdSample/Startup.cs @@ -20,12 +20,19 @@ namespace OpenIdConnect.AzureAdSample { private const string GraphResourceID = "https://graph.windows.net"; - public Startup() + public Startup(IHostingEnvironment env) { - Configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .AddUserSecrets() - .Build(); + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath); + + if (env.IsDevelopment()) + { + // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } @@ -150,17 +157,6 @@ namespace OpenIdConnect.AzureAdSample await context.Response.WriteAsync($""); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/samples/OpenIdConnectSample/Program.cs b/samples/OpenIdConnectSample/Program.cs new file mode 100644 index 0000000000..a81f11dfb0 --- /dev/null +++ b/samples/OpenIdConnectSample/Program.cs @@ -0,0 +1,24 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace OpenIdConnectSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/samples/OpenIdConnectSample/Properties/launchSettings.json b/samples/OpenIdConnectSample/Properties/launchSettings.json index 5a0163016a..557b6921e2 100644 --- a/samples/OpenIdConnectSample/Properties/launchSettings.json +++ b/samples/OpenIdConnectSample/Properties/launchSettings.json @@ -15,13 +15,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "OpenIdConnectSample": { + "commandName": "Project", "launchBrowser": true, "launchUrl": "http://localhost:42023", "environmentVariables": { - "Hosting:Environment": "Development", - "ASPNET_server.urls": "http://localhost:42023" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "http://localhost:42023" } } } diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index ff68b471fa..c2f831e199 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -15,12 +15,19 @@ namespace OpenIdConnectSample { public class Startup { - public Startup() + public Startup(IHostingEnvironment env) { - Configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .AddUserSecrets() - .Build(); + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath); + + if (env.IsDevelopment()) + { + // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } @@ -96,17 +103,6 @@ namespace OpenIdConnectSample await context.Response.WriteAsync($""); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/samples/SocialSample/Program.cs b/samples/SocialSample/Program.cs new file mode 100644 index 0000000000..386819e6f5 --- /dev/null +++ b/samples/SocialSample/Program.cs @@ -0,0 +1,50 @@ +using System.IO; +using System.Reflection; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; + +namespace SocialSample +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build(); + + var host = new WebHostBuilder() + .UseKestrel(options => + { + //Configure SSL + var serverCertificate = LoadCertificate(); + options.UseHttps(serverCertificate); + }) + .UseConfiguration(config) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + + private static X509Certificate2 LoadCertificate() + { + var socialSampleAssembly = typeof(Startup).GetTypeInfo().Assembly; + var embeddedFileProvider = new EmbeddedFileProvider(socialSampleAssembly, "SocialSample"); + var certificateFileInfo = embeddedFileProvider.GetFileInfo("compiler/resources/cert.pfx"); + using (var certificateStream = certificateFileInfo.CreateReadStream()) + { + byte[] certificatePayload; + using (var memoryStream = new MemoryStream()) + { + certificateStream.CopyTo(memoryStream); + certificatePayload = memoryStream.ToArray(); + } + + return new X509Certificate2(certificatePayload, "testPassword"); + } + } + } +} diff --git a/samples/SocialSample/Properties/launchSettings.json b/samples/SocialSample/Properties/launchSettings.json index e9d26ad03e..903a815886 100644 --- a/samples/SocialSample/Properties/launchSettings.json +++ b/samples/SocialSample/Properties/launchSettings.json @@ -13,15 +13,16 @@ "launchBrowser": true, "launchUrl": "https://localhost:44318/", "environmentVariables": { - "ASPNET_ENV": "Development" + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "web": { - "commandName": "web", + "SocialSample": { + "commandName": "Project", "launchBrowser": true, "launchUrl": "https://localhost:54541/", "environmentVariables": { - "Hosting:Environment": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_SERVER.URLS": "https://localhost:54541/" } } } diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index 7cad7de849..f8c7495d34 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -1,11 +1,8 @@ using System; -using System.IO; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; -using System.Reflection; using System.Security.Claims; -using System.Security.Cryptography.X509Certificates; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; @@ -20,7 +17,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Authentication; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; @@ -29,13 +25,20 @@ namespace SocialSample /* Note all servers must use the same address and port because these are pre-registered with the various providers. */ public class Startup { - public Startup() + public Startup(IHostingEnvironment env) { - Configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .AddJsonFile("config.json") - .AddUserSecrets() - .Build(); + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json"); + + if (env.IsDevelopment()) + { + // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } @@ -343,40 +346,6 @@ namespace SocialSample await context.Response.WriteAsync(""); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel(options => - { - //Configure SSL - var serverCertificate = LoadCertificate(); - options.UseHttps(serverCertificate); - }) - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); - } - - private static X509Certificate2 LoadCertificate() - { - var socialSampleAssembly = typeof(Startup).GetTypeInfo().Assembly; - var embeddedFileProvider = new EmbeddedFileProvider(socialSampleAssembly, "SocialSample"); - var certificateFileInfo = embeddedFileProvider.GetFileInfo("compiler/resources/cert.pfx"); - using (var certificateStream = certificateFileInfo.CreateReadStream()) - { - byte[] certificatePayload; - using (var memoryStream = new MemoryStream()) - { - certificateStream.CopyTo(memoryStream); - certificatePayload = memoryStream.ToArray(); - } - - return new X509Certificate2(certificatePayload, "testPassword"); - } - } } } diff --git a/samples/SocialSample/config.json b/samples/SocialSample/appsettings.json similarity index 100% rename from samples/SocialSample/config.json rename to samples/SocialSample/appsettings.json diff --git a/samples/SocialSample/project.json b/samples/SocialSample/project.json index faf517703f..fb19d3ec2a 100644 --- a/samples/SocialSample/project.json +++ b/samples/SocialSample/project.json @@ -19,7 +19,7 @@ "emitEntryPoint": true }, "frameworks": { - "net451": {}, + "net451": { }, "netcoreapp1.0": { "imports": [ "dnxcore50" @@ -35,7 +35,7 @@ "userSecretsId": "aspnet5-SocialSample-20151210111056", "publishOptions": { "include": [ - "config.json", + "appsettings.json", "project.json", "web.config" ]