This repository was archived by the owner on Feb 6, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathIdentityServerConfig.cs
More file actions
121 lines (103 loc) · 4.54 KB
/
Copy pathIdentityServerConfig.cs
File metadata and controls
121 lines (103 loc) · 4.54 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
116
117
118
119
120
121
using IdentityServer4;
using IdentityServer4.Models;
using System.Collections.Generic;
using IdentityModel;
namespace RoomMonitor
{
public static class IdentityServerConfig
{
// Identity resources are data like user ID, name, or email address of a user.
// An identity resource has a unique name, and you can assign arbitrary claim types to it.
// These claims will then be included in the identity token for the user.
// The client will use the scope parameter to request access to an identity resource.
public static IEnumerable<IdentityResource> GetIdentityResources()
{
var userProfile = new IdentityResource(
name: RoomMonitorConstants.IdentityResourceNames.UserProfile,
displayName: "User Profile Data",
claimTypes: new[] { JwtClaimTypes.Email, JwtClaimTypes.Role, RoomMonitorConstants.ClaimTypes.Hotel }
);
var deviceProfile = new IdentityResource(
name: RoomMonitorConstants.IdentityResourceNames.DeviceProfile,
displayName: "Device Profile Data",
claimTypes: new[] { RoomMonitorConstants.ClaimTypes.Hotel }
);
return new IdentityResource[]
{
new IdentityResources.OpenId(),
// new IdentityResources.Profile(),
userProfile,
deviceProfile
};
}
public static IEnumerable<ApiResource> GetApiResources()
{
return new ApiResource[]
{
// new ApiResource(IdentityServerConstants.LocalApi.ScopeName),
new ApiResource {
Name = RoomMonitorConstants.ApiResourceName,
Scopes = {
new Scope {
Name = RoomMonitorConstants.Scopes.UserScope,
DisplayName = "User Access to RoomMonitor API",
UserClaims = {JwtClaimTypes.Role, RoomMonitorConstants.ClaimTypes.Hotel}
},
new Scope {
Name = RoomMonitorConstants.Scopes.DeviceScope,
DisplayName = "Device Access to RoomMonitor API",
UserClaims = {RoomMonitorConstants.ClaimTypes.Hotel}
}
}
}
};
}
public static IEnumerable<Client> GetClients()
{
return new Client[]
{
// SPA client using code flow + pkce
new Client
{
ClientId = RoomMonitorConstants.ClientIds.SpaClient,
ClientName = "RoomMonitor Angular SPA Client",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
RequireConsent = false,
AccessTokenLifetime = 3600,
RedirectUris =
{
"http://localhost:5000",
"http://localhost:5000/silent-renew.html",
"http://localhost:5000/popup.html",
},
PostLogoutRedirectUris = { "http://localhost:5000" },
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
RoomMonitorConstants.Scopes.UserScope,
RoomMonitorConstants.IdentityResourceNames.UserProfile
}
},
new Client {
ClientId = RoomMonitorConstants.ClientIds.DeviceClient,
ClientName = "RoomMonitor Sensor Device Client",
AccessTokenLifetime = 3600,
IdentityTokenLifetime = 3600,
AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowOfflineAccess = true,
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.OfflineAccess,
RoomMonitorConstants.Scopes.DeviceScope,
RoomMonitorConstants.IdentityResourceNames.DeviceProfile
}
}
};
}
}
}