// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
{
///
/// Specifies events which the invokes to enable developer control over the authentication process.
///
public class OpenIdConnectEvents : RemoteAuthenticationEvents, IOpenIdConnectEvents
{
///
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
///
public Func OnAuthenticationFailed { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked after security token validation if an authorization code is present in the protocol message.
///
public Func OnAuthorizationCodeReceived { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked when a protocol message is first received.
///
public Func OnMessageReceived { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked before redirecting to the identity provider to authenticate.
///
public Func OnRedirectToIdentityProvider { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked before redirecting to the identity provider to sign out.
///
public Func OnRedirectToIdentityProviderForSignOut { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked when a request is received on the RemoteSignOutPath.
///
public Func OnRemoteSignOut { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
///
public Func OnTokenResponseReceived { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked when an IdToken has been validated and produced an AuthenticationTicket.
///
public Func OnTokenValidated { get; set; } = context => TaskCache.CompletedTask;
///
/// Invoked when user information is retrieved from the UserInfoEndpoint.
///
public Func OnUserInformationReceived { get; set; } = context => TaskCache.CompletedTask;
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
public virtual Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context) => OnAuthorizationCodeReceived(context);
public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
public virtual Task RedirectToIdentityProvider(RedirectContext context) => OnRedirectToIdentityProvider(context);
public virtual Task RedirectToIdentityProviderForSignOut(RedirectContext context) => OnRedirectToIdentityProviderForSignOut(context);
public virtual Task RemoteSignOut(RemoteSignOutContext context) => OnRemoteSignOut(context);
public virtual Task TokenResponseReceived(TokenResponseReceivedContext context) => OnTokenResponseReceived(context);
public virtual Task TokenValidated(TokenValidatedContext context) => OnTokenValidated(context);
public virtual Task UserInformationReceived(UserInformationReceivedContext context) => OnUserInformationReceived(context);
}
}