This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTestHandlers.cs
More file actions
115 lines (98 loc) · 3.87 KB
/
Copy pathTestHandlers.cs
File metadata and controls
115 lines (98 loc) · 3.87 KB
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
// Copyright (c) .NET Foundation. All rights reserved. See License.txt in the project root for license information.
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Authentication.Tests
{
public class TestAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>, IAuthenticationSignInHandler
{
public TestAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
{ }
public int SignInCount { get; set; }
public int SignOutCount { get; set; }
public int ForbidCount { get; set; }
public int ChallengeCount { get; set; }
public int AuthenticateCount { get; set; }
protected override Task HandleChallengeAsync(AuthenticationProperties properties)
{
ChallengeCount++;
return Task.CompletedTask;
}
protected override Task HandleForbiddenAsync(AuthenticationProperties properties)
{
ForbidCount++;
return Task.CompletedTask;
}
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
AuthenticateCount++;
var principal = new ClaimsPrincipal();
var id = new ClaimsIdentity();
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, Scheme.Name, ClaimValueTypes.String, Scheme.Name));
principal.AddIdentity(id);
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties(), Scheme.Name)));
}
public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
{
SignInCount++;
return Task.CompletedTask;
}
public Task SignOutAsync(AuthenticationProperties properties)
{
SignOutCount++;
return Task.CompletedTask;
}
}
public class TestHandler : IAuthenticationSignInHandler
{
public AuthenticationScheme Scheme { get; set; }
public int SignInCount { get; set; }
public int SignOutCount { get; set; }
public int ForbidCount { get; set; }
public int ChallengeCount { get; set; }
public int AuthenticateCount { get; set; }
public Task<AuthenticateResult> AuthenticateAsync()
{
AuthenticateCount++;
var principal = new ClaimsPrincipal();
var id = new ClaimsIdentity();
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, Scheme.Name, ClaimValueTypes.String, Scheme.Name));
principal.AddIdentity(id);
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties(), Scheme.Name)));
}
public Task ChallengeAsync(AuthenticationProperties properties)
{
ChallengeCount++;
return Task.CompletedTask;
}
public Task ForbidAsync(AuthenticationProperties properties)
{
ForbidCount++;
return Task.CompletedTask;
}
public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
{
Scheme = scheme;
return Task.CompletedTask;
}
public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
{
SignInCount++;
return Task.CompletedTask;
}
public Task SignOutAsync(AuthenticationProperties properties)
{
SignOutCount++;
return Task.CompletedTask;
}
}
public class TestHandler2 : TestHandler
{
}
public class TestHandler3 : TestHandler
{
}
}