-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLocalDevelopmentUser.cs
44 lines (37 loc) · 1.57 KB
/
LocalDevelopmentUser.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
using System.Collections.ObjectModel;
using System.Security.Claims;
using Digdir.Domain.Dialogporten.Application.Externals.Presentation;
namespace Digdir.Domain.Dialogporten.GraphQL.Common.Authentication;
internal sealed class LocalDevelopmentUser : IUser
{
private readonly ClaimsPrincipal _principal = new(new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.Name, "Local Development User"),
new Claim(ClaimTypes.NameIdentifier, "local-development-user"),
new Claim("pid", "03886595947"),
new Claim("scope", string.Join(" ", AuthorizationScope.AllScopes.Value)),
new Claim("consumer",
"""
{
"authority": "iso6523-actorid-upis",
"ID": "0192:991825827"
}
""")
}));
public ClaimsPrincipal GetPrincipal() => _principal;
}
internal static class AuthorizationScope
{
public const string EndUser = "digdir:dialogporten";
public const string ServiceProvider = "digdir:dialogporten.serviceprovider";
public const string ServiceProviderSearch = "digdir:dialogporten.serviceprovider.search";
public const string Testing = "digdir:dialogporten.developer.test";
internal static readonly Lazy<IReadOnlyCollection<string>> AllScopes = new(GetAll);
private static ReadOnlyCollection<string> GetAll() =>
typeof(AuthorizationScope)
.GetFields()
.Where(x => x.IsLiteral && !x.IsInitOnly && x.DeclaringType == typeof(string))
.Select(x => (string)x.GetRawConstantValue()!)
.ToList()
.AsReadOnly();
}