React to OpenIdConnect event changes.

This commit is contained in:
Chris R 2016-03-25 16:10:46 -07:00
Родитель 3edb06d983
Коммит 00f660b50d
2 изменённых файлов: 8 добавлений и 16 удалений

Просмотреть файл

@ -20,19 +20,13 @@ namespace MusicStore.Mocks.OpenIdConnect
return Task.FromResult(0);
}
internal static Task AuthenticationValidated(AuthenticationValidatedContext context)
{
eventsFired.Add(nameof(AuthenticationValidated));
return Task.FromResult(0);
}
internal static Task AuthorizationResponseRecieved(AuthorizationResponseReceivedContext context)
internal static Task TokenValidated(TokenValidatedContext context)
{
Helpers.ThrowIfConditionFailed(() => context.Ticket != null, "context.Ticket is null.");
Helpers.ThrowIfConditionFailed(() => context.Ticket.Principal != null, "context.Ticket.Principal is null.");
Helpers.ThrowIfConditionFailed(() => context.Ticket.Principal.Identity != null, "context.Ticket.Principal.Identity is null.");
Helpers.ThrowIfConditionFailed(() => !string.IsNullOrWhiteSpace(context.Ticket.Principal.Identity.Name), "context.Ticket.Principal.Identity.Name is null.");
eventsFired.Add(nameof(AuthorizationResponseRecieved));
eventsFired.Add(nameof(TokenValidated));
return Task.FromResult(0);
}
@ -43,10 +37,9 @@ namespace MusicStore.Mocks.OpenIdConnect
eventsFired.Add(nameof(AuthorizationCodeReceived));
// Verify all events are fired.
if (eventsFired.Contains(nameof(RedirectToAuthenticationEndpoint)) &&
if (eventsFired.Contains(nameof(RedirectToIdentityProvider)) &&
eventsFired.Contains(nameof(MessageReceived)) &&
eventsFired.Contains(nameof(AuthenticationValidated)) &&
eventsFired.Contains(nameof(AuthorizationResponseRecieved)) &&
eventsFired.Contains(nameof(TokenValidated)) &&
eventsFired.Contains(nameof(AuthorizationCodeReceived)))
{
((ClaimsIdentity)context.Ticket.Principal.Identity).AddClaim(new Claim("ManageStore", "Allowed"));
@ -55,9 +48,9 @@ namespace MusicStore.Mocks.OpenIdConnect
return Task.FromResult(0);
}
internal static Task RedirectToAuthenticationEndpoint(RedirectContext context)
internal static Task RedirectToIdentityProvider(RedirectContext context)
{
eventsFired.Add(nameof(RedirectToAuthenticationEndpoint));
eventsFired.Add(nameof(RedirectToIdentityProvider));
if (context.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
{

Просмотреть файл

@ -130,9 +130,8 @@ namespace MusicStore
{
OnMessageReceived = TestOpenIdConnectEvents.MessageReceived,
OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived,
OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint,
OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated,
OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved
OnRedirectToIdentityProvider = TestOpenIdConnectEvents.RedirectToIdentityProvider,
OnTokenValidated = TestOpenIdConnectEvents.TokenValidated,
}
};
options.TokenValidationParameters.ValidateLifetime = false;