From 39fc5ebdc4d9101d0a5205a22e1fec5b64d35d89 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 11 Mar 2015 14:38:40 -0700 Subject: [PATCH] Making the tests robust And some general cleanup --- src/MusicStore/Startup.cs | 4 +- src/MusicStore/StartupNtlmAuthentication.cs | 4 +- src/MusicStore/StartupOpenIdConnect.cs | 17 ++- test/E2ETests/Common/DeploymentUtility.cs | 20 ++- test/E2ETests/NtlmAuthentationTest.cs | 13 +- test/E2ETests/OpenIdConnectTests.cs | 15 +-- test/E2ETests/PublishAndRunTests.cs | 13 +- test/E2ETests/SmokeTests.cs | 16 +-- .../Mocks/Common/CustomStateDataFormat.cs | 4 +- .../Mocks/Facebook/FacebookNotifications.cs | 2 +- .../Mocks/Google/GoogleNotifications.cs | 2 +- .../MicrosoftAccountNotifications.cs | 2 +- .../Mocks/StartupOpenIdConnectTesting.cs | 46 +++---- .../shared/Mocks/StartupSocialTesting.cs | 123 ++++++++---------- 14 files changed, 123 insertions(+), 158 deletions(-) diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 810fc0e4ca..778d207b79 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -1,16 +1,14 @@ using System; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Authentication; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using MusicStore.Models; -using Microsoft.AspNet.Authorization; namespace MusicStore { diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index d07492d50d..54bcff927e 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -1,19 +1,17 @@ using System; using System.Security.Claims; using System.Security.Principal; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; -using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Server.WebListener; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using Microsoft.Net.Http.Server; using MusicStore.Models; -using Microsoft.AspNet.Authorization; namespace MusicStore { diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index 7f43e1ff9f..413e272d98 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -1,16 +1,14 @@ using System; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Authentication; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using MusicStore.Models; -using Microsoft.AspNet.Authorization; namespace MusicStore { @@ -64,6 +62,12 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); + services.ConfigureOpenIdConnectAuthentication(options => + { + options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; + options.ClientId = "[ClientId]"; + }); + // Add MVC services to the services container services.AddMvc(); @@ -114,12 +118,7 @@ namespace MusicStore app.UseIdentity(); // Create an Azure Active directory application and copy paste the following - // https://github.com/aspnet/Security/issues/113 - app.UseOpenIdConnectAuthentication(options => - { - options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; - options.ClientId = "[ClientId]"; - }); + app.UseOpenIdConnectAuthentication(); // Add MVC to the request pipeline app.UseMvc(routes => diff --git a/test/E2ETests/Common/DeploymentUtility.cs b/test/E2ETests/Common/DeploymentUtility.cs index 029976f8e0..404257a536 100644 --- a/test/E2ETests/Common/DeploymentUtility.cs +++ b/test/E2ETests/Common/DeploymentUtility.cs @@ -302,9 +302,9 @@ namespace E2ETests private static string SwitchPathToRuntimeFlavor(RuntimeFlavor runtimeFlavor, RuntimeArchitecture runtimeArchitecture, ILogger logger) { - var currentRuntime = Environment.GetCommandLineArgs().First(); + var runtimePath = Environment.GetCommandLineArgs().First(); logger.LogInformation(string.Empty); - logger.LogInformation("Current runtime is : {0}", currentRuntime); + logger.LogInformation("Current runtime path is : {0}", runtimePath); var replaceStr = new StringBuilder(). Append("dnx"). @@ -313,13 +313,21 @@ namespace E2ETests Append((runtimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64"). ToString(); - currentRuntime = Regex.Replace(currentRuntime, "dnx-(clr|coreclr)-win-(x86|x64)", replaceStr, RegexOptions.IgnoreCase); - currentRuntime = Path.GetDirectoryName(currentRuntime); + runtimePath = Regex.Replace(runtimePath, "dnx-(clr|coreclr)-win-(x86|x64)", replaceStr, RegexOptions.IgnoreCase); + runtimePath = Path.GetDirectoryName(runtimePath); // Tweak the %PATH% to the point to the right RUNTIMEFLAVOR. - Environment.SetEnvironmentVariable("PATH", currentRuntime + ";" + Environment.GetEnvironmentVariable("PATH")); + Environment.SetEnvironmentVariable("PATH", runtimePath + ";" + Environment.GetEnvironmentVariable("PATH")); - var runtimeName = new DirectoryInfo(currentRuntime).Parent.Name; + var runtimeDirectoryInfo = new DirectoryInfo(runtimePath); + if (!runtimeDirectoryInfo.Exists) + { + throw new Exception( + string.Format("Requested runtime at location '{0}' does not exist. Please make sure it is installed before running test.", + runtimeDirectoryInfo.FullName)); + } + + var runtimeName = runtimeDirectoryInfo.Parent.Name; logger.LogInformation(string.Empty); logger.LogInformation("Changing to use runtime : {runtimeName}", runtimeName); return runtimeName; diff --git a/test/E2ETests/NtlmAuthentationTest.cs b/test/E2ETests/NtlmAuthentationTest.cs index 17eeec123f..24c90ffe09 100644 --- a/test/E2ETests/NtlmAuthentationTest.cs +++ b/test/E2ETests/NtlmAuthentationTest.cs @@ -32,7 +32,7 @@ namespace E2ETests SiteName = "MusicStoreNtlmAuthentication" //This is configured in the NtlmAuthentication.config }; - var testStartTime = DateTime.Now; + var stopwatch = Stopwatch.StartNew(); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); @@ -53,19 +53,15 @@ namespace E2ETests HttpResponseMessage response = null; string responseContent = null; - var initializationCompleteTime = DateTime.MinValue; //Request to base address and check if various parts of the body are rendered & measure the cold startup time. Helpers.Retry(() => { response = _httpClient.GetAsync(string.Empty).Result; responseContent = response.Content.ReadAsStringAsync().Result; - initializationCompleteTime = DateTime.Now; + _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); }, logger: _logger); - _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", - (initializationCompleteTime - testStartTime).TotalSeconds); - VerifyHomePage(response, responseContent, true); //Check if the user name appears in the page @@ -76,9 +72,8 @@ namespace E2ETests //Should be able to access the store as the Startup adds necessary permissions for the current user AccessStoreWithPermissions(); - var testCompletionTime = DateTime.Now; - _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); - _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); + stopwatch.Stop(); + _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } finally diff --git a/test/E2ETests/OpenIdConnectTests.cs b/test/E2ETests/OpenIdConnectTests.cs index 009e924a4b..3b87f0b7cb 100644 --- a/test/E2ETests/OpenIdConnectTests.cs +++ b/test/E2ETests/OpenIdConnectTests.cs @@ -41,7 +41,7 @@ namespace E2ETests EnvironmentName = "OpenIdConnectTesting" }; - var testStartTime = DateTime.Now; + var stopwatch = Stopwatch.StartNew(); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); @@ -68,27 +68,22 @@ namespace E2ETests HttpResponseMessage response = null; string responseContent = null; - var initializationCompleteTime = DateTime.MinValue; //Request to base address and check if various parts of the body are rendered & measure the cold startup time. Helpers.Retry(() => { response = _httpClient.GetAsync(string.Empty).Result; responseContent = response.Content.ReadAsStringAsync().Result; - initializationCompleteTime = DateTime.Now; + _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); }, logger: _logger); - _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", - (initializationCompleteTime - testStartTime).TotalSeconds); - VerifyHomePage(response, responseContent); // OpenIdConnect login. LoginWithOpenIdConnect(); - var testCompletionTime = DateTime.Now; - _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); - _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); + stopwatch.Stop(); + _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } finally @@ -103,4 +98,4 @@ namespace E2ETests } } } -} +} \ No newline at end of file diff --git a/test/E2ETests/PublishAndRunTests.cs b/test/E2ETests/PublishAndRunTests.cs index 532bb32d13..a0a59a70a0 100644 --- a/test/E2ETests/PublishAndRunTests.cs +++ b/test/E2ETests/PublishAndRunTests.cs @@ -51,7 +51,7 @@ namespace E2ETests BundleApplicationBeforeStart = true }; - var testStartTime = DateTime.Now; + var stopwatch = Stopwatch.StartNew(); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); @@ -72,7 +72,6 @@ namespace E2ETests HttpResponseMessage response = null; string responseContent = null; - var initializationCompleteTime = DateTime.MinValue; //Request to base address and check if various parts of the body are rendered & measure the cold startup time. //Add retry logic since tests are flaky on mono due to connection issues @@ -80,12 +79,9 @@ namespace E2ETests { response = _httpClient.GetAsync(string.Empty).Result; responseContent = response.Content.ReadAsStringAsync().Result; - initializationCompleteTime = DateTime.Now; + _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); }, logger: _logger); - _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", - (initializationCompleteTime - testStartTime).TotalSeconds); - VerifyHomePage(response, responseContent, true); //Static files are served? @@ -99,9 +95,8 @@ namespace E2ETests } } - var testCompletionTime = DateTime.Now; - _logger.LogInformation("[Time]: All tests completed in '{t}' seconds.", (testCompletionTime - initializationCompleteTime).TotalSeconds); - _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds.", (testCompletionTime - testStartTime).TotalSeconds); + stopwatch.Stop(); + _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds.", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } finally diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index 76cd607b80..c5cb874b6c 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Net.Http; using Microsoft.AspNet.Testing.xunit; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using Xunit; namespace E2ETests @@ -105,7 +104,7 @@ namespace E2ETests EnvironmentName = "SocialTesting" }; - var testStartTime = DateTime.Now; + var stopwatch = Stopwatch.StartNew(); var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName)); @@ -132,19 +131,15 @@ namespace E2ETests HttpResponseMessage response = null; string responseContent = null; - var initializationCompleteTime = DateTime.MinValue; //Request to base address and check if various parts of the body are rendered & measure the cold startup time. Helpers.Retry(() => { response = _httpClient.GetAsync(string.Empty).Result; responseContent = response.Content.ReadAsStringAsync().Result; - initializationCompleteTime = DateTime.Now; + _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); }, logger: _logger); - _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", - (initializationCompleteTime - testStartTime).TotalSeconds); - VerifyHomePage(response, responseContent); //Verify the static file middleware can serve static content @@ -228,9 +223,8 @@ namespace E2ETests //MicrosoftAccountLogin LoginWithMicrosoftAccount(); - var testCompletionTime = DateTime.Now; - _logger.LogInformation("[Time]: All tests completed in '{t}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds); - _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", (testCompletionTime - testStartTime).TotalSeconds); + stopwatch.Stop(); + _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } finally @@ -245,4 +239,4 @@ namespace E2ETests } } } -} +} \ No newline at end of file diff --git a/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs b/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs index f14dddb22e..1b68d8d649 100644 --- a/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs +++ b/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNet.Http.Authentication; -using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Http.Authentication; using Newtonsoft.Json; namespace MusicStore.Mocks.Common diff --git a/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs b/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs index e1f7be98c2..c42273b26a 100644 --- a/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs @@ -2,9 +2,9 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Identity; using Microsoft.AspNet.Authentication.Facebook; using Microsoft.AspNet.Authentication.OAuth; +using Microsoft.AspNet.Identity; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.Facebook diff --git a/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs b/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs index 7d79280572..fe8dc6bb99 100644 --- a/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs @@ -2,9 +2,9 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Identity; using Microsoft.AspNet.Authentication.Google; using Microsoft.AspNet.Authentication.OAuth; +using Microsoft.AspNet.Identity; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.Google diff --git a/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs b/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs index 686d90e18c..2402a7a482 100644 --- a/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs @@ -2,9 +2,9 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Identity; using Microsoft.AspNet.Authentication.MicrosoftAccount; using Microsoft.AspNet.Authentication.OAuth; +using Microsoft.AspNet.Identity; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.MicrosoftAccount diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs index a116e53cce..756835779a 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -9,7 +9,6 @@ using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using MusicStore.Mocks.Common; using MusicStore.Mocks.OpenIdConnect; using MusicStore.Models; @@ -53,6 +52,28 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); + services.ConfigureOpenIdConnectAuthentication(options => + { + options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; + options.ClientId = "c99497aa-3ee2-4707-b8a8-c33f51323fef"; + options.BackchannelHttpHandler = new OpenIdConnectBackChannelHttpHandler(); + options.StringDataFormat = new CustomStringDataFormat(); + options.StateDataFormat = new CustomStateDataFormat(); + options.TokenValidationParameters.ValidateLifetime = false; + options.ProtocolValidator.RequireNonce = true; + options.ProtocolValidator.NonceLifetime = TimeSpan.FromDays(36500); + options.UseTokenLifetime = false; + + options.Notifications = new OpenIdConnectAuthenticationNotifications + { + MessageReceived = OpenIdConnectNotifications.MessageReceived, + AuthorizationCodeReceived = OpenIdConnectNotifications.AuthorizationCodeReceived, + RedirectToIdentityProvider = OpenIdConnectNotifications.RedirectToIdentityProvider, + SecurityTokenReceived = OpenIdConnectNotifications.SecurityTokenReceived, + SecurityTokenValidated = OpenIdConnectNotifications.SecurityTokenValidated + }; + }); + // Add MVC services to the services container services.AddMvc(); @@ -103,28 +124,7 @@ namespace MusicStore app.UseIdentity(); // Create an Azure Active directory application and copy paste the following - // https://github.com/aspnet/Security/issues/113 - app.UseOpenIdConnectAuthentication(options => - { - options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; - options.ClientId = "c99497aa-3ee2-4707-b8a8-c33f51323fef"; - options.BackchannelHttpHandler = new OpenIdConnectBackChannelHttpHandler(); - options.StringDataFormat = new CustomStringDataFormat(); - options.StateDataFormat = new CustomStateDataFormat(); - options.TokenValidationParameters.ValidateLifetime = false; - options.ProtocolValidator.RequireNonce = true; - options.ProtocolValidator.NonceLifetime = TimeSpan.FromDays(36500); - options.UseTokenLifetime = false; - - options.Notifications = new OpenIdConnectAuthenticationNotifications - { - MessageReceived = OpenIdConnectNotifications.MessageReceived, - AuthorizationCodeReceived = OpenIdConnectNotifications.AuthorizationCodeReceived, - RedirectToIdentityProvider = OpenIdConnectNotifications.RedirectToIdentityProvider, - SecurityTokenReceived = OpenIdConnectNotifications.SecurityTokenReceived, - SecurityTokenValidated = OpenIdConnectNotifications.SecurityTokenValidated - }; - }); + app.UseOpenIdConnectAuthentication(); // Add MVC to the request pipeline app.UseMvc(routes => diff --git a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs index 0354716637..66819c5973 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Threading.Tasks; using Microsoft.AspNet.Authentication.Facebook; using Microsoft.AspNet.Authentication.Google; using Microsoft.AspNet.Authentication.MicrosoftAccount; @@ -9,13 +8,11 @@ using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Logging.Console; using Microsoft.Framework.Runtime; using MusicStore.Mocks.Common; using MusicStore.Mocks.Facebook; @@ -89,6 +86,55 @@ namespace MusicStore options.Scope.Add("user_checkins"); }); + services.ConfigureGoogleAuthentication(options => + { + options.ClientId = "[ClientId]"; + options.ClientSecret = "[ClientSecret]"; + options.AccessType = "offline"; + options.Notifications = new GoogleAuthenticationNotifications() + { + OnAuthenticated = GoogleNotifications.OnAuthenticated, + OnReturnEndpoint = GoogleNotifications.OnReturnEndpoint, + OnApplyRedirect = GoogleNotifications.OnApplyRedirect + }; + options.StateDataFormat = new CustomStateDataFormat(); + options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler(); + }); + + services.ConfigureTwitterAuthentication(options => + { + options.ConsumerKey = "[ConsumerKey]"; + options.ConsumerSecret = "[ConsumerSecret]"; + options.Notifications = new TwitterAuthenticationNotifications() + { + OnAuthenticated = TwitterNotifications.OnAuthenticated, + OnReturnEndpoint = TwitterNotifications.OnReturnEndpoint, + OnApplyRedirect = TwitterNotifications.OnApplyRedirect + }; + options.StateDataFormat = new CustomTwitterStateDataFormat(); + options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler(); +#if DNX451 + options.BackchannelCertificateValidator = null; +#endif + }); + + services.ConfigureMicrosoftAccountAuthentication(options => + { + options.Caption = "MicrosoftAccount - Requires project changes"; + options.ClientId = "[ClientId]"; + options.ClientSecret = "[ClientSecret]"; + options.Notifications = new MicrosoftAccountAuthenticationNotifications() + { + OnAuthenticated = MicrosoftAccountNotifications.OnAuthenticated, + OnReturnEndpoint = MicrosoftAccountNotifications.OnReturnEndpoint, + OnApplyRedirect = MicrosoftAccountNotifications.OnApplyRedirect + }; + options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(); + options.StateDataFormat = new CustomStateDataFormat(); + options.Scope.Add("wl.basic"); + options.Scope.Add("wl.signin"); + }); + // Add MVC services to the services container services.AddMvc(); @@ -129,26 +175,6 @@ namespace MusicStore // Configure Session. app.UseSession(); - //To gracefully shutdown the server - Not for production scenarios - app.Map("/shutdown", shutdown => - { - shutdown.Run(async context => - { - var appShutdown = context.ApplicationServices.GetService(); - appShutdown.RequestShutdown(); - - await Task.Delay(10 * 1000, appShutdown.ShutdownRequested); - if (appShutdown.ShutdownRequested.IsCancellationRequested) - { - await context.Response.WriteAsync("Shutting down gracefully"); - } - else - { - await context.Response.WriteAsync("Shutting down token not fired"); - } - }); - }); - //Configure SignalR app.UseSignalR(); @@ -160,54 +186,11 @@ namespace MusicStore app.UseFacebookAuthentication(); - app.UseGoogleAuthentication(options => - { - options.ClientId = "[ClientId]"; - options.ClientSecret = "[ClientSecret]"; - options.AccessType = "offline"; - options.Notifications = new GoogleAuthenticationNotifications() - { - OnAuthenticated = GoogleNotifications.OnAuthenticated, - OnReturnEndpoint = GoogleNotifications.OnReturnEndpoint, - OnApplyRedirect = GoogleNotifications.OnApplyRedirect - }; - options.StateDataFormat = new CustomStateDataFormat(); - options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler(); - }); + app.UseGoogleAuthentication(); - app.UseTwitterAuthentication(options => - { - options.ConsumerKey = "[ConsumerKey]"; - options.ConsumerSecret = "[ConsumerSecret]"; - options.Notifications = new TwitterAuthenticationNotifications() - { - OnAuthenticated = TwitterNotifications.OnAuthenticated, - OnReturnEndpoint = TwitterNotifications.OnReturnEndpoint, - OnApplyRedirect = TwitterNotifications.OnApplyRedirect - }; - options.StateDataFormat = new CustomTwitterStateDataFormat(); - options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler(); -#if DNX451 - options.BackchannelCertificateValidator = null; -#endif - }); + app.UseTwitterAuthentication(); - app.UseMicrosoftAccountAuthentication(options => - { - options.Caption = "MicrosoftAccount - Requires project changes"; - options.ClientId = "[ClientId]"; - options.ClientSecret = "[ClientSecret]"; - options.Notifications = new MicrosoftAccountAuthenticationNotifications() - { - OnAuthenticated = MicrosoftAccountNotifications.OnAuthenticated, - OnReturnEndpoint = MicrosoftAccountNotifications.OnReturnEndpoint, - OnApplyRedirect = MicrosoftAccountNotifications.OnApplyRedirect - }; - options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(); - options.StateDataFormat = new CustomStateDataFormat(); - options.Scope.Add("wl.basic"); - options.Scope.Add("wl.signin"); - }); + app.UseMicrosoftAccountAuthentication(); // Add MVC to the request pipeline app.UseMvc(routes => @@ -231,4 +214,4 @@ namespace MusicStore SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait(); } } -} +} \ No newline at end of file