-
Notifications
You must be signed in to change notification settings - Fork 14
/
Config.cs
175 lines (157 loc) · 7.02 KB
/
Config.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
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
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace Yuan.IdentityServer4.EF
{
public static class Config
{
public static IEnumerable<IdentityResource> GetIdentityResources =>
new IdentityResource[]
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
};
public static IEnumerable<ApiScope> GetApiScopes =>
new ApiScope[]
{
new ApiScope("client_scope1"),
new ApiScope("password_scope1"),
new ApiScope("Implicit_scope1"),
new ApiScope("code_scope1"),
new ApiScope("hybrid_scope1")
};
public static IEnumerable<ApiResource> GetApiResources =>
new ApiResource[]
{
new ApiResource("client.api1","client.api1")
{
Scopes={"client_scope1" },
},
new ApiResource("password.api1","password.api1")
{
Scopes={ "password_scope1" },
UserClaims={JwtClaimTypes.Role}, //添加Cliam 角色类型
ApiSecrets={new Secret("apipwd".Sha256())}
},
new ApiResource("implicit.api1","implicit.api1")
{
Scopes={ "Implicit_scope1" },
UserClaims={JwtClaimTypes.Role}, //添加Cliam 角色类型
ApiSecrets={new Secret("apipwd".Sha256())}
},
new ApiResource("code.api1","code.api1")
{
Scopes={ "code_scope1" },
UserClaims={JwtClaimTypes.Role}, //添加Cliam 角色类型
ApiSecrets={new Secret("apipwd".Sha256())}
},
new ApiResource("hybrid.api1","hybrid.api1")
{
Scopes={ "hybrid_scope1" },
UserClaims={JwtClaimTypes.Role}, //添加Cliam 角色类型
ApiSecrets={new Secret("apipwd".Sha256())}
}
};
public static IEnumerable<Client> GetClients =>
new Client[]
{
//客户端模式
new Client
{
ClientId = "credentials_client",
ClientName = "Client Credentials Client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
AllowedScopes = { "client_scope1" }
},
// 密码模式
new Client
{
ClientId = "password_client",
ClientName = "Resource Owner Password",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
AllowedScopes = { "password_scope1" }
},
//简化模式
new Client
{
ClientId = "Implicit_client",
ClientName = "Implicit Auth",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris ={
"http://localhost:5002/signin-oidc", //跳转登录到的客户端的地址
},
// RedirectUris = {"http://localhost:5002/auth.html" }, //跳转登出到的客户端的地址
PostLogoutRedirectUris ={
"http://localhost:5002/signout-callback-oidc",
},
//ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"Implicit_scope1"
},
//允许将token通过浏览器传递
AllowAccessTokensViaBrowser=true,
// 是否需要同意授权 (默认是false)
RequireConsent=true
},
//授权码模式
new Client
{
ClientId = "code_client",
ClientName = "code Auth",
AllowedGrantTypes = GrantTypes.Code,
RedirectUris ={
"http://localhost:5002/signin-oidc", //跳转登录到的客户端的地址
},
// RedirectUris = {"http://localhost:5002/auth.html" }, //跳转登出到的客户端的地址
PostLogoutRedirectUris ={
"http://localhost:5002/signout-callback-oidc",
},
ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"code_scope1"
},
//允许将token通过浏览器传递
AllowAccessTokensViaBrowser=true,
// 是否需要同意授权 (默认是false)
RequireConsent=true
},
//混合模式
new Client
{
ClientId = "hybrid_client",
ClientName = "hybrid Auth",
ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
AllowedGrantTypes = GrantTypes.Hybrid,
RequirePkce = false,//v4.x需要配置这个
RedirectUris ={
"http://localhost:5002/signin-oidc", //跳转登录到的客户端的地址
},
// RedirectUris = {"http://localhost:5002/auth.html" }, //跳转登出到的客户端的地址
PostLogoutRedirectUris ={
"http://localhost:5002/signout-callback-oidc",
},
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"hybrid_scope1"
},
//允许将token通过浏览器传递
AllowAccessTokensViaBrowser=true,
// AllowOfflineAccess=true,
// 是否需要同意授权 (默认是false)
RequireConsent=true
}
};
}
}