// 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.AspNet.Http;
///
/// Specifies events which the invokes to enable developer control over the authentication process. />
///
namespace Microsoft.AspNet.Authentication.OpenIdConnectBearer
{
///
/// OpenIdConnect bearer token middleware events.
///
public class OpenIdConnectBearerEvents : IOpenIdConnectBearerEvents
{
///
/// 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 => Task.FromResult(0);
///
/// Invoked when a protocol message is first received.
///
public Func OnMessageReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked with the security token that has been extracted from the protocol message.
///
public Func OnSecurityTokenReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
///
public Func OnSecurityTokenValidated { get; set; } = context => Task.FromResult(0);
///
/// Invoked to apply a challenge sent back to the caller.
///
public Func OnApplyChallenge { get; set; } = context =>
{
context.HttpContext.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge);
return Task.FromResult(0);
};
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
public virtual Task SecurityTokenReceived(SecurityTokenReceivedContext context) => OnSecurityTokenReceived(context);
public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
public virtual Task ApplyChallenge(AuthenticationChallengeContext context) => OnApplyChallenge(context);
}
}