Reacting to new middleware options pattern

This commit is contained in:
John Luo 2016-01-08 19:47:02 -08:00
parent 01e9616828
commit 6d91b8d9fd
4 changed files with 62 additions and 64 deletions

View File

@ -120,27 +120,28 @@ namespace MusicStore
app.UseIdentity(); app.UseIdentity();
// Create an Azure Active directory application and copy paste the following // Create an Azure Active directory application and copy paste the following
app.UseOpenIdConnectAuthentication(options => var options = new OpenIdConnectOptions
{ {
options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; Authority = "https://login.windows.net/[tenantName].onmicrosoft.com",
options.ClientId = "c99497aa-3ee2-4707-b8a8-c33f51323fef"; ClientId = "c99497aa-3ee2-4707-b8a8-c33f51323fef",
options.BackchannelHttpHandler = new OpenIdConnectBackChannelHttpHandler(); BackchannelHttpHandler = new OpenIdConnectBackChannelHttpHandler(),
options.StringDataFormat = new CustomStringDataFormat(); StringDataFormat = new CustomStringDataFormat(),
options.StateDataFormat = new CustomStateDataFormat(); StateDataFormat = new CustomStateDataFormat(),
options.TokenValidationParameters.ValidateLifetime = false; UseTokenLifetime = false,
options.ProtocolValidator.RequireNonce = true;
options.ProtocolValidator.NonceLifetime = TimeSpan.FromDays(36500);
options.UseTokenLifetime = false;
options.Events = new OpenIdConnectEvents Events = new OpenIdConnectEvents
{ {
OnMessageReceived = TestOpenIdConnectEvents.MessageReceived, OnMessageReceived = TestOpenIdConnectEvents.MessageReceived,
OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived, OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived,
OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint, OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint,
OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated, OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated,
OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved
}; }
}); };
options.TokenValidationParameters.ValidateLifetime = false;
options.ProtocolValidator.RequireNonce = true;
options.ProtocolValidator.NonceLifetime = TimeSpan.FromDays(36500);
app.UseOpenIdConnectAuthentication(options);
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(routes => app.UseMvc(routes =>

View File

@ -128,67 +128,64 @@ namespace MusicStore
// Add cookie-based authentication to the request pipeline // Add cookie-based authentication to the request pipeline
app.UseIdentity(); app.UseIdentity();
app.UseFacebookAuthentication(options => app.UseFacebookAuthentication(new FacebookOptions
{ {
options.AppId = "[AppId]"; AppId = "[AppId]",
options.AppSecret = "[AppSecret]"; AppSecret = "[AppSecret]",
options.Events = new OAuthEvents() Events = new OAuthEvents()
{ {
OnCreatingTicket = TestFacebookEvents.OnCreatingTicket, OnCreatingTicket = TestFacebookEvents.OnCreatingTicket,
OnTicketReceived = TestFacebookEvents.OnTicketReceived, OnTicketReceived = TestFacebookEvents.OnTicketReceived,
OnRedirectToAuthorizationEndpoint = TestFacebookEvents.RedirectToAuthorizationEndpoint OnRedirectToAuthorizationEndpoint = TestFacebookEvents.RedirectToAuthorizationEndpoint
}; },
options.BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler(); BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler(),
options.StateDataFormat = new CustomStateDataFormat(); StateDataFormat = new CustomStateDataFormat(),
options.Scope.Add("email"); Scope = { "email", "read_friendlists", "user_checkins" }
options.Scope.Add("read_friendlists");
options.Scope.Add("user_checkins");
}); });
app.UseGoogleAuthentication(options => app.UseGoogleAuthentication(new GoogleOptions
{ {
options.ClientId = "[ClientId]"; ClientId = "[ClientId]",
options.ClientSecret = "[ClientSecret]"; ClientSecret = "[ClientSecret]",
options.AccessType = "offline"; AccessType = "offline",
options.Events = new OAuthEvents() Events = new OAuthEvents()
{ {
OnCreatingTicket = TestGoogleEvents.OnCreatingTicket, OnCreatingTicket = TestGoogleEvents.OnCreatingTicket,
OnTicketReceived = TestGoogleEvents.OnTicketReceived, OnTicketReceived = TestGoogleEvents.OnTicketReceived,
OnRedirectToAuthorizationEndpoint = TestGoogleEvents.RedirectToAuthorizationEndpoint OnRedirectToAuthorizationEndpoint = TestGoogleEvents.RedirectToAuthorizationEndpoint
}; },
options.StateDataFormat = new CustomStateDataFormat(); StateDataFormat = new CustomStateDataFormat(),
options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler(); BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler()
}); });
app.UseTwitterAuthentication(options => app.UseTwitterAuthentication(new TwitterOptions
{ {
options.ConsumerKey = "[ConsumerKey]"; ConsumerKey = "[ConsumerKey]",
options.ConsumerSecret = "[ConsumerSecret]"; ConsumerSecret = "[ConsumerSecret]",
options.Events = new TwitterEvents() Events = new TwitterEvents()
{ {
OnCreatingTicket = TestTwitterEvents.OnCreatingTicket, OnCreatingTicket = TestTwitterEvents.OnCreatingTicket,
OnTicketReceived = TestTwitterEvents.OnTicketReceived, OnTicketReceived = TestTwitterEvents.OnTicketReceived,
OnRedirectToAuthorizationEndpoint = TestTwitterEvents.RedirectToAuthorizationEndpoint OnRedirectToAuthorizationEndpoint = TestTwitterEvents.RedirectToAuthorizationEndpoint
}; },
options.StateDataFormat = new CustomTwitterStateDataFormat(); StateDataFormat = new CustomTwitterStateDataFormat(),
options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler(); BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler()
}); });
app.UseMicrosoftAccountAuthentication(options => app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions
{ {
options.DisplayName = "MicrosoftAccount - Requires project changes"; DisplayName = "MicrosoftAccount - Requires project changes",
options.ClientId = "[ClientId]"; ClientId = "[ClientId]",
options.ClientSecret = "[ClientSecret]"; ClientSecret = "[ClientSecret]",
options.Events = new OAuthEvents() Events = new OAuthEvents()
{ {
OnCreatingTicket = TestMicrosoftAccountEvents.OnCreatingTicket, OnCreatingTicket = TestMicrosoftAccountEvents.OnCreatingTicket,
OnTicketReceived = TestMicrosoftAccountEvents.OnTicketReceived, OnTicketReceived = TestMicrosoftAccountEvents.OnTicketReceived,
OnRedirectToAuthorizationEndpoint = TestMicrosoftAccountEvents.RedirectToAuthorizationEndpoint OnRedirectToAuthorizationEndpoint = TestMicrosoftAccountEvents.RedirectToAuthorizationEndpoint
}; },
options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(); BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler(),
options.StateDataFormat = new CustomStateDataFormat(); StateDataFormat = new CustomStateDataFormat(),
options.Scope.Add("wl.basic"); Scope = { "wl.basic", "wl.signin" }
options.Scope.Add("wl.signin");
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline

View File

@ -158,22 +158,22 @@ namespace MusicStore
// Add cookie-based authentication to the request pipeline // Add cookie-based authentication to the request pipeline
app.UseIdentity(); app.UseIdentity();
app.UseFacebookAuthentication(options => app.UseFacebookAuthentication(new FacebookOptions
{ {
options.AppId = "550624398330273"; AppId = "550624398330273",
options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954"; AppSecret = "10e56a291d6b618da61b1e0dae3a8954"
}); });
app.UseGoogleAuthentication(options => app.UseGoogleAuthentication(new GoogleOptions
{ {
options.ClientId = "995291875932-0rt7417v5baevqrno24kv332b7d6d30a.apps.googleusercontent.com"; ClientId = "995291875932-0rt7417v5baevqrno24kv332b7d6d30a.apps.googleusercontent.com",
options.ClientSecret = "J_AT57H5KH_ItmMdu0r6PfXm"; ClientSecret = "J_AT57H5KH_ItmMdu0r6PfXm"
}); });
app.UseTwitterAuthentication(options => app.UseTwitterAuthentication(new TwitterOptions
{ {
options.ConsumerKey = "lDSPIu480ocnXYZ9DumGCDw37"; ConsumerKey = "lDSPIu480ocnXYZ9DumGCDw37",
options.ConsumerSecret = "fpo0oWRNc3vsZKlZSq1PyOSoeXlJd7NnG4Rfc94xbFXsdcc3nH"; ConsumerSecret = "fpo0oWRNc3vsZKlZSq1PyOSoeXlJd7NnG4Rfc94xbFXsdcc3nH"
}); });
// The MicrosoftAccount service has restrictions that prevent the use of // The MicrosoftAccount service has restrictions that prevent the use of
@ -192,11 +192,11 @@ namespace MusicStore
// The sample app can then be run via: // The sample app can then be run via:
// dnx . web // dnx . web
app.UseMicrosoftAccountAuthentication(options => app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions
{ {
options.DisplayName = "MicrosoftAccount - Requires project changes"; DisplayName = "MicrosoftAccount - Requires project changes",
options.ClientId = "000000004012C08A"; ClientId = "000000004012C08A",
options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL"; ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL"
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline

View File

@ -133,10 +133,10 @@ namespace MusicStore
app.UseIdentity(); app.UseIdentity();
// Create an Azure Active directory application and copy paste the following // Create an Azure Active directory application and copy paste the following
app.UseOpenIdConnectAuthentication(options => app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{ {
options.Authority = "https://login.windows.net/[tenantName].onmicrosoft.com"; Authority = "https://login.windows.net/[tenantName].onmicrosoft.com",
options.ClientId = "[ClientId]"; ClientId = "[ClientId]"
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline