This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
/
AuthenticationManager.cs
132 lines (105 loc) · 5.19 KB
/
AuthenticationManager.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// 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.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features.Authentication;
namespace Microsoft.AspNetCore.Http.Authentication
{
[Obsolete("This is obsolete and will be removed in a future version. See https://go.microsoft.com/fwlink/?linkid=845470.")]
public abstract class AuthenticationManager
{
/// <summary>
/// Constant used to represent the automatic scheme
/// </summary>
public const string AutomaticScheme = "Automatic";
public abstract HttpContext HttpContext { get; }
public abstract IEnumerable<AuthenticationDescription> GetAuthenticationSchemes();
public abstract Task<AuthenticateInfo> GetAuthenticateInfoAsync(string authenticationScheme);
// Will remove once callees have been updated
public abstract Task AuthenticateAsync(AuthenticateContext context);
public virtual async Task<ClaimsPrincipal> AuthenticateAsync(string authenticationScheme)
{
return (await GetAuthenticateInfoAsync(authenticationScheme))?.Principal;
}
public virtual Task ChallengeAsync()
{
return ChallengeAsync(properties: null);
}
public virtual Task ChallengeAsync(AuthenticationProperties properties)
{
return ChallengeAsync(authenticationScheme: AutomaticScheme, properties: properties);
}
public virtual Task ChallengeAsync(string authenticationScheme)
{
if (string.IsNullOrEmpty(authenticationScheme))
{
throw new ArgumentException(nameof(authenticationScheme));
}
return ChallengeAsync(authenticationScheme: authenticationScheme, properties: null);
}
// Leave it up to authentication handler to do the right thing for the challenge
public virtual Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties)
{
if (string.IsNullOrEmpty(authenticationScheme))
{
throw new ArgumentException(nameof(authenticationScheme));
}
return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Automatic);
}
public virtual Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal)
{
if (string.IsNullOrEmpty(authenticationScheme))
{
throw new ArgumentException(nameof(authenticationScheme));
}
if (principal == null)
{
throw new ArgumentNullException(nameof(principal));
}
return SignInAsync(authenticationScheme, principal, properties: null);
}
/// <summary>
/// Creates a challenge for the authentication manager with <see cref="ChallengeBehavior.Forbidden"/>.
/// </summary>
/// <returns>A <see cref="Task"/> that represents the asynchronous challenge operation.</returns>
public virtual Task ForbidAsync()
=> ForbidAsync(AutomaticScheme, properties: null);
public virtual Task ForbidAsync(string authenticationScheme)
{
if (authenticationScheme == null)
{
throw new ArgumentNullException(nameof(authenticationScheme));
}
return ForbidAsync(authenticationScheme, properties: null);
}
// Deny access (typically a 403)
public virtual Task ForbidAsync(string authenticationScheme, AuthenticationProperties properties)
{
if (authenticationScheme == null)
{
throw new ArgumentNullException(nameof(authenticationScheme));
}
return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Forbidden);
}
/// <summary>
/// Creates a challenge for the authentication manager with <see cref="ChallengeBehavior.Forbidden"/>.
/// </summary>
/// <param name="properties">Additional arbitrary values which may be used by particular authentication types.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous challenge operation.</returns>
public virtual Task ForbidAsync(AuthenticationProperties properties)
=> ForbidAsync(AutomaticScheme, properties);
public abstract Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior);
public abstract Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties);
public virtual Task SignOutAsync(string authenticationScheme)
{
if (authenticationScheme == null)
{
throw new ArgumentNullException(nameof(authenticationScheme));
}
return SignOutAsync(authenticationScheme, properties: null);
}
public abstract Task SignOutAsync(string authenticationScheme, AuthenticationProperties properties);
}
}