-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
CertificateAuthenticationEvents.cs
51 lines (44 loc) · 2.3 KB
/
CertificateAuthenticationEvents.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.AspNetCore.Authentication.Certificate;
/// <summary>
/// This default implementation of the IBasicAuthenticationEvents may be used if the
/// application only needs to override a few of the interface methods.
/// This may be used as a base class or may be instantiated directly.
/// </summary>
public class CertificateAuthenticationEvents
{
/// <summary>
/// A delegate assigned to this property will be invoked when the authentication fails.
/// </summary>
public Func<CertificateAuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.CompletedTask;
/// <summary>
/// A delegate assigned to this property will be invoked when a certificate has passed basic validation, but where custom validation may be needed.
/// </summary>
/// <remarks>
/// You must provide a delegate for this property for authentication to occur.
/// In your delegate you should construct an authentication principal from the user details,
/// attach it to the context.Principal property and finally call context.Success();
/// </remarks>
public Func<CertificateValidatedContext, Task> OnCertificateValidated { get; set; } = context => Task.CompletedTask;
/// <summary>
/// Invoked before a challenge is sent back to the caller.
/// </summary>
public Func<CertificateChallengeContext, Task> OnChallenge { get; set; } = context => Task.CompletedTask;
/// <summary>
/// Invoked when a certificate fails authentication.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public virtual Task AuthenticationFailed(CertificateAuthenticationFailedContext context) => OnAuthenticationFailed(context);
/// <summary>
/// Invoked after a certificate has been validated
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public virtual Task CertificateValidated(CertificateValidatedContext context) => OnCertificateValidated(context);
/// <summary>
/// Invoked before a challenge is sent back to the caller.
/// </summary>
public virtual Task Challenge(CertificateChallengeContext context) => OnChallenge(context);
}