-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
201 lines (184 loc) · 8.26 KB
/
Config.cs
File metadata and controls
201 lines (184 loc) · 8.26 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
namespace NetShop.IdentityService
{
public static class Config
{
public static IEnumerable<IdentityResource> IdentityResources =>
new IdentityResource[]
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email(),
new IdentityResource
{
Name = "roles",
DisplayName = "Roles",
Description = "User roles",
UserClaims = { JwtClaimTypes.Role }
}
};
public static IEnumerable<ApiScope> ApiScopes =>
new List<ApiScope>
{
new ApiScope("ProductService.Write","Ürün servisi yazma izni."),
new ApiScope("ProductService.Read","Ürün servisi okuma izni.")
};
public static IEnumerable<ApiResource> ApiResources =>
new List<ApiResource>
{
new ApiResource("ProductService")
{
Scopes = {"ProductService.Write", "ProductService.Read" },
ApiSecrets = { new Secret("product-service".Sha256()) },
UserClaims = new []{ JwtClaimTypes.Role, JwtClaimTypes.Email }
}
};
public static IEnumerable<Client> Clients =>
new List<Client>
{
// SPA
new Client
{
ClientId = "AngularClient",
ClientName = "Angular Client",
RequireClientSecret = false,
AllowedScopes = {
"ProductService.Write",
"ProductService.Read",
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Email,
IdentityServerConstants.StandardScopes.OfflineAccess,
"roles"
},
RedirectUris = {"http://localhost:4200/signin-callback", "http://localhost:4200/silent-callback"},
AllowedCorsOrigins = {"http://localhost:4200"},
PostLogoutRedirectUris = {"http://localhost:4200"},
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
//RequireConsent = true
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.ReUse,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = 96000,
AccessTokenLifetime = 3600
},
// Client Credentals
new Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = {
"ProductService.Write",
"ProductService.Read",
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Email,
"roles"
},
},
// resource owner password grant client
new Client
{
ClientId = "ResourceOwnerClient",
ClientName = "Resource Owner Client",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = {
"ProductService.Write",
"ProductService.Read",
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Email,
IdentityServerConstants.StandardScopes.OfflineAccess,
"roles"
},
AllowOfflineAccess = true,
AccessTokenLifetime = 60 * 60,
RefreshTokenUsage = TokenUsage.ReUse,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = (60 * 60) + 900,
RequirePkce = false,
},
// OpenID Connect hybrid flow client (MVC)
new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.Hybrid,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris = { "http://localhost:5002/signin-oidc" },
PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },
AllowedScopes = {
"ProductService.Write",
"ProductService.Read",
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Email,
"roles"
},
AllowOfflineAccess = true
},
// JavaScript Client
new Client
{
ClientId = "js",
ClientName = "JavaScript Client",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
RedirectUris = { "http://localhost:5003/callback.html" },
PostLogoutRedirectUris = { "http://localhost:5003/index.html" },
AllowedCorsOrigins = { "http://localhost:5003" },
AllowedScopes =
{
"ProductService.Write",
"ProductService.Read",
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Email,
"roles"
}
}
};
public static IEnumerable<TestUser> Users =>
new List<TestUser>
{
new TestUser
{
SubjectId = "test-user1",
Username = "test-user1",
Password = "12345",
Claims =
{
new Claim(JwtRegisteredClaimNames.Email, "test-user@gmail.com"),
new Claim(JwtRegisteredClaimNames.FamilyName, "User"),
new Claim(JwtRegisteredClaimNames.GivenName, "Test"),
new Claim("role", "admin"),
new Claim("authority","true")
}
}
};
}
}