diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index cd15a132b8..ad21b4d664 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -64,31 +64,6 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.AddFacebookAuthentication(options => - { - options.AppId = "550624398330273"; - options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954"; - }); - - services.AddGoogleAuthentication(options => - { - options.ClientId = "977382855444.apps.googleusercontent.com"; - options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN"; - }); - - services.AddTwitterAuthentication(options => - { - options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam"; - options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8"; - }); - - services.AddMicrosoftAccountAuthentication(options => - { - options.Caption = "MicrosoftAccount - Requires project changes"; - options.ClientId = "000000004012C08A"; - options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL"; - }); - services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => @@ -111,7 +86,7 @@ namespace MusicStore services.AddSingleton(); // Configure Auth - services.Configure(options => + services.AddAuthorization(options => { options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); @@ -179,11 +154,23 @@ namespace MusicStore // Add cookie-based authentication to the request pipeline app.UseIdentity(); - app.UseFacebookAuthentication(); + app.UseFacebookAuthentication(options => + { + options.AppId = "550624398330273"; + options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954"; + }); - app.UseGoogleAuthentication(); + app.UseGoogleAuthentication(options => + { + options.ClientId = "977382855444.apps.googleusercontent.com"; + options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN"; + }); - app.UseTwitterAuthentication(); + app.UseTwitterAuthentication(options => + { + options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam"; + options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8"; + }); // The MicrosoftAccount service has restrictions that prevent the use of http://localhost:5001/ for test applications. // As such, here is how to change this sample to uses http://ktesting.com:5001/ instead. @@ -200,7 +187,12 @@ namespace MusicStore // The sample app can then be run via: // dnx . web - app.UseMicrosoftAccountAuthentication(); + app.UseMicrosoftAccountAuthentication(options => + { + options.Caption = "MicrosoftAccount - Requires project changes"; + options.ClientId = "000000004012C08A"; + options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL"; + }); // Add MVC to the request pipeline app.UseMvc(routes => diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index a3c22bd2c9..f03d2b1160 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -73,12 +73,6 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.AddOpenIdConnectAuthentication(options => - { - options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; - options.ClientId = "[ClientId]"; - }); - services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => @@ -134,7 +128,11 @@ namespace MusicStore app.UseIdentity(); // Create an Azure Active directory application and copy paste the following - app.UseOpenIdConnectAuthentication(); + app.UseOpenIdConnectAuthentication(options => + { + options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; + options.ClientId = "[ClientId]"; + }); // Add MVC to the request pipeline app.UseMvc(routes => diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs index 9a2592596a..592a380483 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -65,28 +65,6 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.AddOpenIdConnectAuthentication(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.Events = new OpenIdConnectEvents - { - OnMessageReceived = TestOpenIdConnectEvents.MessageReceived, - OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived, - OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint, - OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated, - OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved - }; - }); - services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => @@ -142,7 +120,27 @@ namespace MusicStore app.UseIdentity(); // Create an Azure Active directory application and copy paste the following - app.UseOpenIdConnectAuthentication(); + 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.Events = new OpenIdConnectEvents + { + OnMessageReceived = TestOpenIdConnectEvents.MessageReceived, + OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived, + OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint, + OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated, + OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved + }; + }); // 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 d9272e7d89..6b7dc48f24 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs @@ -75,69 +75,6 @@ namespace MusicStore .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.AddFacebookAuthentication(options => - { - options.AppId = "[AppId]"; - options.AppSecret = "[AppSecret]"; - options.Events = new OAuthEvents() - { - OnAuthenticated = TestFacebookEvents.OnAuthenticated, - OnReturnEndpoint = TestFacebookEvents.OnReturnEndpoint, - OnApplyRedirect = TestFacebookEvents.OnApplyRedirect - }; - options.BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler(); - options.StateDataFormat = new CustomStateDataFormat(); - options.Scope.Add("email"); - options.Scope.Add("read_friendlists"); - options.Scope.Add("user_checkins"); - }); - - services.AddGoogleAuthentication(options => - { - options.ClientId = "[ClientId]"; - options.ClientSecret = "[ClientSecret]"; - options.AccessType = "offline"; - options.Events = new OAuthEvents() - { - OnAuthenticated = TestGoogleEvents.OnAuthenticated, - OnReturnEndpoint = TestGoogleEvents.OnReturnEndpoint, - OnApplyRedirect = TestGoogleEvents.OnApplyRedirect - }; - options.StateDataFormat = new CustomStateDataFormat(); - options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler(); - }); - - services.AddTwitterAuthentication(options => - { - options.ConsumerKey = "[ConsumerKey]"; - options.ConsumerSecret = "[ConsumerSecret]"; - options.Events = new TwitterEvents() - { - OnAuthenticated = TestTwitterEvents.OnAuthenticated, - OnReturnEndpoint = TestTwitterEvents.OnReturnEndpoint, - OnApplyRedirect = TestTwitterEvents.OnApplyRedirect - }; - options.StateDataFormat = new CustomTwitterStateDataFormat(); - options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler(); - }); - - services.AddMicrosoftAccountAuthentication(options => - { - options.Caption = "MicrosoftAccount - Requires project changes"; - options.ClientId = "[ClientId]"; - options.ClientSecret = "[ClientSecret]"; - options.Events = new OAuthEvents() - { - OnAuthenticated = TestMicrosoftAccountEvents.OnAuthenticated, - OnReturnEndpoint = TestMicrosoftAccountEvents.OnReturnEndpoint, - OnApplyRedirect = TestMicrosoftAccountEvents.OnApplyRedirect - }; - options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(); - options.StateDataFormat = new CustomStateDataFormat(); - options.Scope.Add("wl.basic"); - options.Scope.Add("wl.signin"); - }); - services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => @@ -160,7 +97,7 @@ namespace MusicStore services.AddSingleton(); // Configure Auth - services.Configure(options => + services.AddAuthorization(options => { options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); @@ -192,13 +129,68 @@ namespace MusicStore // Add cookie-based authentication to the request pipeline app.UseIdentity(); - app.UseFacebookAuthentication(); + app.UseFacebookAuthentication(options => + { + options.AppId = "[AppId]"; + options.AppSecret = "[AppSecret]"; + options.Events = new OAuthEvents() + { + OnAuthenticated = TestFacebookEvents.OnAuthenticated, + OnReturnEndpoint = TestFacebookEvents.OnReturnEndpoint, + OnApplyRedirect = TestFacebookEvents.OnApplyRedirect + }; + options.BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler(); + options.StateDataFormat = new CustomStateDataFormat(); + options.Scope.Add("email"); + options.Scope.Add("read_friendlists"); + options.Scope.Add("user_checkins"); + }); - app.UseGoogleAuthentication(); + app.UseGoogleAuthentication(options => + { + options.ClientId = "[ClientId]"; + options.ClientSecret = "[ClientSecret]"; + options.AccessType = "offline"; + options.Events = new OAuthEvents() + { + OnAuthenticated = TestGoogleEvents.OnAuthenticated, + OnReturnEndpoint = TestGoogleEvents.OnReturnEndpoint, + OnApplyRedirect = TestGoogleEvents.OnApplyRedirect + }; + options.StateDataFormat = new CustomStateDataFormat(); + options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler(); + }); - app.UseTwitterAuthentication(); + app.UseTwitterAuthentication(options => + { + options.ConsumerKey = "[ConsumerKey]"; + options.ConsumerSecret = "[ConsumerSecret]"; + options.Events = new TwitterEvents() + { + OnAuthenticated = TestTwitterEvents.OnAuthenticated, + OnReturnEndpoint = TestTwitterEvents.OnReturnEndpoint, + OnApplyRedirect = TestTwitterEvents.OnApplyRedirect + }; + options.StateDataFormat = new CustomTwitterStateDataFormat(); + options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler(); + }); - app.UseMicrosoftAccountAuthentication(); + app.UseMicrosoftAccountAuthentication(options => + { + options.Caption = "MicrosoftAccount - Requires project changes"; + options.ClientId = "[ClientId]"; + options.ClientSecret = "[ClientSecret]"; + options.Events = new OAuthEvents() + { + OnAuthenticated = TestMicrosoftAccountEvents.OnAuthenticated, + OnReturnEndpoint = TestMicrosoftAccountEvents.OnReturnEndpoint, + OnApplyRedirect = TestMicrosoftAccountEvents.OnApplyRedirect + }; + options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(); + options.StateDataFormat = new CustomStateDataFormat(); + options.Scope.Add("wl.basic"); + options.Scope.Add("wl.signin"); + }); // Add MVC to the request pipeline app.UseMvc(routes =>