React to OpenIdConnect event changes.
This commit is contained in:
parent
3edb06d983
commit
00f660b50d
|
|
@ -20,19 +20,13 @@ namespace MusicStore.Mocks.OpenIdConnect
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Task AuthenticationValidated(AuthenticationValidatedContext context)
|
internal static Task TokenValidated(TokenValidatedContext context)
|
||||||
{
|
|
||||||
eventsFired.Add(nameof(AuthenticationValidated));
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static Task AuthorizationResponseRecieved(AuthorizationResponseReceivedContext context)
|
|
||||||
{
|
{
|
||||||
Helpers.ThrowIfConditionFailed(() => context.Ticket != null, "context.Ticket is null.");
|
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 != null, "context.Ticket.Principal is null.");
|
||||||
Helpers.ThrowIfConditionFailed(() => context.Ticket.Principal.Identity != null, "context.Ticket.Principal.Identity 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.");
|
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);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,10 +37,9 @@ namespace MusicStore.Mocks.OpenIdConnect
|
||||||
eventsFired.Add(nameof(AuthorizationCodeReceived));
|
eventsFired.Add(nameof(AuthorizationCodeReceived));
|
||||||
|
|
||||||
// Verify all events are fired.
|
// Verify all events are fired.
|
||||||
if (eventsFired.Contains(nameof(RedirectToAuthenticationEndpoint)) &&
|
if (eventsFired.Contains(nameof(RedirectToIdentityProvider)) &&
|
||||||
eventsFired.Contains(nameof(MessageReceived)) &&
|
eventsFired.Contains(nameof(MessageReceived)) &&
|
||||||
eventsFired.Contains(nameof(AuthenticationValidated)) &&
|
eventsFired.Contains(nameof(TokenValidated)) &&
|
||||||
eventsFired.Contains(nameof(AuthorizationResponseRecieved)) &&
|
|
||||||
eventsFired.Contains(nameof(AuthorizationCodeReceived)))
|
eventsFired.Contains(nameof(AuthorizationCodeReceived)))
|
||||||
{
|
{
|
||||||
((ClaimsIdentity)context.Ticket.Principal.Identity).AddClaim(new Claim("ManageStore", "Allowed"));
|
((ClaimsIdentity)context.Ticket.Principal.Identity).AddClaim(new Claim("ManageStore", "Allowed"));
|
||||||
|
|
@ -55,9 +48,9 @@ namespace MusicStore.Mocks.OpenIdConnect
|
||||||
return Task.FromResult(0);
|
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)
|
if (context.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,8 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
OnMessageReceived = TestOpenIdConnectEvents.MessageReceived,
|
OnMessageReceived = TestOpenIdConnectEvents.MessageReceived,
|
||||||
OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived,
|
OnAuthorizationCodeReceived = TestOpenIdConnectEvents.AuthorizationCodeReceived,
|
||||||
OnRedirectToAuthenticationEndpoint = TestOpenIdConnectEvents.RedirectToAuthenticationEndpoint,
|
OnRedirectToIdentityProvider = TestOpenIdConnectEvents.RedirectToIdentityProvider,
|
||||||
OnAuthenticationValidated = TestOpenIdConnectEvents.AuthenticationValidated,
|
OnTokenValidated = TestOpenIdConnectEvents.TokenValidated,
|
||||||
OnAuthorizationResponseReceived = TestOpenIdConnectEvents.AuthorizationResponseRecieved
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
options.TokenValidationParameters.ValidateLifetime = false;
|
options.TokenValidationParameters.ValidateLifetime = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue