This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Constants.cs
340 lines (302 loc) · 14.6 KB
/
Constants.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// 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.Models;
using System;
using System.Collections.Generic;
namespace IdentityServer4
{
internal static class Constants
{
public const string IdentityServerName = "IdentityServer4";
public const string IdentityServerAuthenticationType = IdentityServerName;
public const string ExternalAuthenticationMethod = "external";
public const string DefaultHashAlgorithm = "SHA256";
public static readonly TimeSpan DefaultCookieTimeSpan = TimeSpan.FromHours(10);
public static readonly TimeSpan DefaultCacheDuration = TimeSpan.FromMinutes(60);
public static readonly List<string> SupportedResponseTypes = new List<string>
{
OidcConstants.ResponseTypes.Code,
OidcConstants.ResponseTypes.Token,
OidcConstants.ResponseTypes.IdToken,
OidcConstants.ResponseTypes.IdTokenToken,
OidcConstants.ResponseTypes.CodeIdToken,
OidcConstants.ResponseTypes.CodeToken,
OidcConstants.ResponseTypes.CodeIdTokenToken
};
public static readonly Dictionary<string, string> ResponseTypeToGrantTypeMapping = new Dictionary<string, string>
{
{ OidcConstants.ResponseTypes.Code, GrantType.AuthorizationCode },
{ OidcConstants.ResponseTypes.Token, GrantType.Implicit },
{ OidcConstants.ResponseTypes.IdToken, GrantType.Implicit },
{ OidcConstants.ResponseTypes.IdTokenToken, GrantType.Implicit },
{ OidcConstants.ResponseTypes.CodeIdToken, GrantType.Hybrid },
{ OidcConstants.ResponseTypes.CodeToken, GrantType.Hybrid },
{ OidcConstants.ResponseTypes.CodeIdTokenToken, GrantType.Hybrid }
};
public static readonly List<string> AllowedGrantTypesForAuthorizeEndpoint = new List<string>
{
GrantType.AuthorizationCode,
GrantType.Implicit,
GrantType.Hybrid
};
public static readonly List<string> SupportedCodeChallengeMethods = new List<string>
{
OidcConstants.CodeChallengeMethods.Plain,
OidcConstants.CodeChallengeMethods.Sha256
};
public enum ScopeRequirement
{
None,
ResourceOnly,
IdentityOnly,
Identity
}
public static readonly Dictionary<string, ScopeRequirement> ResponseTypeToScopeRequirement = new Dictionary<string, ScopeRequirement>
{
{ OidcConstants.ResponseTypes.Code, ScopeRequirement.None },
{ OidcConstants.ResponseTypes.Token, ScopeRequirement.ResourceOnly },
{ OidcConstants.ResponseTypes.IdToken, ScopeRequirement.IdentityOnly },
{ OidcConstants.ResponseTypes.IdTokenToken, ScopeRequirement.Identity },
{ OidcConstants.ResponseTypes.CodeIdToken, ScopeRequirement.Identity },
{ OidcConstants.ResponseTypes.CodeToken, ScopeRequirement.Identity },
{ OidcConstants.ResponseTypes.CodeIdTokenToken, ScopeRequirement.Identity }
};
public static readonly Dictionary<string, IEnumerable<string>> AllowedResponseModesForGrantType = new Dictionary<string, IEnumerable<string>>
{
{ GrantType.AuthorizationCode, new[] { OidcConstants.ResponseModes.Query, OidcConstants.ResponseModes.FormPost, OidcConstants.ResponseModes.Fragment } },
{ GrantType.Hybrid, new[] { OidcConstants.ResponseModes.Fragment, OidcConstants.ResponseModes.FormPost }},
{ GrantType.Implicit, new[] { OidcConstants.ResponseModes.Fragment, OidcConstants.ResponseModes.FormPost }}
};
public static readonly List<string> SupportedResponseModes = new List<string>
{
OidcConstants.ResponseModes.FormPost,
OidcConstants.ResponseModes.Query,
OidcConstants.ResponseModes.Fragment
};
public static string[] SupportedSubjectTypes =
{
"pairwise", "public"
};
public static class SigningAlgorithms
{
public const string RSA_SHA_256 = "RS256";
}
public static readonly List<string> SupportedDisplayModes = new List<string>
{
OidcConstants.DisplayModes.Page,
OidcConstants.DisplayModes.Popup,
OidcConstants.DisplayModes.Touch,
OidcConstants.DisplayModes.Wap
};
public static readonly List<string> SupportedPromptModes = new List<string>
{
OidcConstants.PromptModes.None,
OidcConstants.PromptModes.Login,
OidcConstants.PromptModes.Consent,
OidcConstants.PromptModes.SelectAccount
};
public static class KnownAcrValues
{
public const string HomeRealm = "idp:";
public const string Tenant = "tenant:";
public static readonly string[] All = { HomeRealm, Tenant };
}
public static Dictionary<string, int> ProtectedResourceErrorStatusCodes = new Dictionary<string, int>
{
{ OidcConstants.ProtectedResourceErrors.InvalidToken, 401 },
{ OidcConstants.ProtectedResourceErrors.ExpiredToken, 401 },
{ OidcConstants.ProtectedResourceErrors.InvalidRequest, 400 },
{ OidcConstants.ProtectedResourceErrors.InsufficientScope, 403 }
};
public static readonly Dictionary<string, IEnumerable<string>> ScopeToClaimsMapping = new Dictionary<string, IEnumerable<string>>
{
{ IdentityServerConstants.StandardScopes.Profile, new[]
{
JwtClaimTypes.Name,
JwtClaimTypes.FamilyName,
JwtClaimTypes.GivenName,
JwtClaimTypes.MiddleName,
JwtClaimTypes.NickName,
JwtClaimTypes.PreferredUserName,
JwtClaimTypes.Profile,
JwtClaimTypes.Picture,
JwtClaimTypes.WebSite,
JwtClaimTypes.Gender,
JwtClaimTypes.BirthDate,
JwtClaimTypes.ZoneInfo,
JwtClaimTypes.Locale,
JwtClaimTypes.UpdatedAt
}},
{ IdentityServerConstants.StandardScopes.Email, new[]
{
JwtClaimTypes.Email,
JwtClaimTypes.EmailVerified
}},
{ IdentityServerConstants.StandardScopes.Address, new[]
{
JwtClaimTypes.Address
}},
{ IdentityServerConstants.StandardScopes.Phone, new[]
{
JwtClaimTypes.PhoneNumber,
JwtClaimTypes.PhoneNumberVerified
}},
{ IdentityServerConstants.StandardScopes.OpenId, new[]
{
JwtClaimTypes.Subject
}}
};
public static class UIConstants
{
// the limit after which old messages are purged
public const int CookieMessageThreshold = 2;
public static class DefaultRoutePathParams
{
public const string Error = "errorId";
public const string Login = "returnUrl";
public const string Consent = "returnUrl";
public const string Logout = "logoutId";
public const string EndSessionCallback = "endSessionId";
public const string Custom = "returnUrl";
public const string UserCode = "userCode";
}
public static class DefaultRoutePaths
{
public const string Login = "/account/login";
public const string Logout = "/account/logout";
public const string Consent = "/consent";
public const string Error = "/home/error";
public const string DeviceVerification = "/device";
}
}
public static class EndpointNames
{
public const string Authorize = "Authorize";
public const string Token = "Token";
public const string DeviceAuthorization = "DeviceAuthorization";
public const string Discovery = "Discovery";
public const string Introspection = "Introspection";
public const string Revocation = "Revocation";
public const string EndSession = "Endsession";
public const string CheckSession = "Checksession";
public const string UserInfo = "Userinfo";
}
public static class ProtocolRoutePaths
{
public const string ConnectPathPrefix = "connect";
public const string Authorize = ConnectPathPrefix + "/authorize";
public const string AuthorizeCallback = Authorize + "/callback";
public const string DiscoveryConfiguration = ".well-known/openid-configuration";
public const string DiscoveryWebKeys = DiscoveryConfiguration + "/jwks";
public const string Token = ConnectPathPrefix + "/token";
public const string Revocation = ConnectPathPrefix + "/revocation";
public const string UserInfo = ConnectPathPrefix + "/userinfo";
public const string Introspection = ConnectPathPrefix + "/introspect";
public const string EndSession = ConnectPathPrefix + "/endsession";
public const string EndSessionCallback = EndSession + "/callback";
public const string CheckSession = ConnectPathPrefix + "/checksession";
public const string DeviceAuthorization = ConnectPathPrefix + "/deviceauthorization";
public const string MtlsPathPrefix = ConnectPathPrefix + "/mtls";
public const string MtlsToken = MtlsPathPrefix + "/token";
public const string MtlsRevocation = MtlsPathPrefix + "/revocation";
public const string MtlsIntrospection = MtlsPathPrefix + "/introspect";
public const string MtlsDeviceAuthorization = MtlsPathPrefix + "/deviceauthorization";
public static readonly string[] CorsPaths =
{
DiscoveryConfiguration,
DiscoveryWebKeys,
Token,
UserInfo,
Revocation
};
}
public static class EnvironmentKeys
{
public const string IdentityServerBasePath = "idsvr:IdentityServerBasePath";
[Obsolete("The IdentityServerOrigin constant is obsolete.")]
public const string IdentityServerOrigin = "idsvr:IdentityServerOrigin"; // todo: deprecate
public const string SignOutCalled = "idsvr:IdentityServerSignOutCalled";
}
public static class TokenTypeHints
{
public const string RefreshToken = "refresh_token";
public const string AccessToken = "access_token";
}
public static List<string> SupportedTokenTypeHints = new List<string>
{
TokenTypeHints.RefreshToken,
TokenTypeHints.AccessToken
};
public static class RevocationErrors
{
public const string UnsupportedTokenType = "unsupported_token_type";
}
public class Filters
{
// filter for claims from an incoming access token (e.g. used at the user profile endpoint)
public static readonly string[] ProtocolClaimsFilter = {
JwtClaimTypes.AccessTokenHash,
JwtClaimTypes.Audience,
JwtClaimTypes.AuthorizedParty,
JwtClaimTypes.AuthorizationCodeHash,
JwtClaimTypes.ClientId,
JwtClaimTypes.Expiration,
JwtClaimTypes.IssuedAt,
JwtClaimTypes.Issuer,
JwtClaimTypes.JwtId,
JwtClaimTypes.Nonce,
JwtClaimTypes.NotBefore,
JwtClaimTypes.ReferenceTokenId,
JwtClaimTypes.SessionId,
JwtClaimTypes.Scope
};
// filter list for claims returned from profile service prior to creating tokens
public static readonly string[] ClaimsServiceFilterClaimTypes = {
// TODO: consider JwtClaimTypes.AuthenticationContextClassReference,
JwtClaimTypes.AccessTokenHash,
JwtClaimTypes.Audience,
JwtClaimTypes.AuthenticationMethod,
JwtClaimTypes.AuthenticationTime,
JwtClaimTypes.AuthorizedParty,
JwtClaimTypes.AuthorizationCodeHash,
JwtClaimTypes.ClientId,
JwtClaimTypes.Expiration,
JwtClaimTypes.IdentityProvider,
JwtClaimTypes.IssuedAt,
JwtClaimTypes.Issuer,
JwtClaimTypes.JwtId,
JwtClaimTypes.Nonce,
JwtClaimTypes.NotBefore,
JwtClaimTypes.ReferenceTokenId,
JwtClaimTypes.SessionId,
JwtClaimTypes.Subject,
JwtClaimTypes.Scope,
JwtClaimTypes.Confirmation
};
public static readonly string[] JwtRequestClaimTypesFilter = {
JwtClaimTypes.Audience,
JwtClaimTypes.Expiration,
JwtClaimTypes.IssuedAt,
JwtClaimTypes.Issuer,
JwtClaimTypes.NotBefore,
JwtClaimTypes.JwtId
};
}
public static class WsFedSignOut
{
public const string LogoutUriParameterName = "wa";
public const string LogoutUriParameterValue = "wsignoutcleanup1.0";
}
public static class AuthorizationParamsStore
{
public const string MessageStoreIdParameterName = "authzId";
}
public static class CurveOids
{
public const string P256 = "1.2.840.10045.3.1.7";
public const string P384 = "1.3.132.0.34";
public const string P521 = "1.3.132.0.35";
}
}
}