Repository navigation
Expand file tree
/
Copy pathClaimsTransformationHandler.cs
More file actions
84 lines (73 loc) · 2.49 KB
/
Copy pathClaimsTransformationHandler.cs
File metadata and controls
84 lines (73 loc) · 2.49 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
// 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.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features.Authentication;
namespace Microsoft.AspNetCore.Authentication
{
/// <summary>
/// Handler that applies ClaimsTransformation to authentication
/// </summary>
public class ClaimsTransformationHandler : IAuthenticationHandler
{
private readonly IClaimsTransformer _transform;
public ClaimsTransformationHandler(IClaimsTransformer transform)
{
_transform = transform;
}
public IAuthenticationHandler PriorHandler { get; set; }
public async Task AuthenticateAsync(AuthenticateContext context)
{
if (PriorHandler != null)
{
await PriorHandler.AuthenticateAsync(context);
if (_transform != null && context?.Principal != null)
{
context.Authenticated(
await _transform.TransformAsync(context.Principal),
context.Properties,
context.Description);
}
}
}
public Task ChallengeAsync(ChallengeContext context)
{
if (PriorHandler != null)
{
return PriorHandler.ChallengeAsync(context);
}
return Task.FromResult(0);
}
public void GetDescriptions(DescribeSchemesContext context)
{
if (PriorHandler != null)
{
PriorHandler.GetDescriptions(context);
}
}
public Task SignInAsync(SignInContext context)
{
if (PriorHandler != null)
{
return PriorHandler.SignInAsync(context);
}
return Task.FromResult(0);
}
public Task SignOutAsync(SignOutContext context)
{
if (PriorHandler != null)
{
return PriorHandler.SignOutAsync(context);
}
return Task.FromResult(0);
}
public void RegisterAuthenticationHandler(IHttpAuthenticationFeature auth)
{
PriorHandler = auth.Handler;
auth.Handler = this;
}
public void UnregisterAuthenticationHandler(IHttpAuthenticationFeature auth)
{
auth.Handler = PriorHandler;
}
}
}