-
Notifications
You must be signed in to change notification settings - Fork 397
/
TokenValidationParameters.cs
679 lines (613 loc) · 28.3 KB
/
TokenValidationParameters.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Claims;
using Microsoft.IdentityModel.Logging;
namespace Microsoft.IdentityModel.Tokens
{
/// <summary>
/// Definition for AudienceValidator.
/// </summary>
/// <param name="audiences">The audiences found in the <see cref="SecurityToken"/>.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> being validated.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns>true if the audience is considered valid.</returns>
public delegate bool AudienceValidator(IEnumerable<string> audiences, SecurityToken securityToken, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for IssuerSigningKeyResolver.
/// </summary>
/// <param name="token">The <see cref="string"/> representation of the token that is being validated.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> that is being validated. It may be null.</param>
/// <param name="kid">A key identifier. It may be null.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns>A <see cref="SecurityKey"/> to use when validating a signature.</returns>
public delegate IEnumerable<SecurityKey> IssuerSigningKeyResolver(string token, SecurityToken securityToken, string kid, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for IssuerSigningKeyValidator.
/// </summary>
/// <param name="securityKey">The <see cref="SecurityKey"/> that signed the <see cref="SecurityToken"/>.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> being validated.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
public delegate bool IssuerSigningKeyValidator(SecurityKey securityKey, SecurityToken securityToken, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for IssuerValidator.
/// </summary>
/// <param name="issuer">The issuer to validate.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> that is being validated.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns>The issuer to use when creating the "Claim"(s) in a "ClaimsIdentity".</returns>
/// <remarks>The delegate should return a non null string that represents the 'issuer'. If null a default value will be used.</remarks>
public delegate string IssuerValidator(string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for LifetimeValidator.
/// </summary>
/// <param name="notBefore">The 'notBefore' time found in the <see cref="SecurityToken"/>.</param>
/// <param name="expires">The 'expiration' time found in the <see cref="SecurityToken"/>.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> being validated.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
public delegate bool LifetimeValidator(DateTime? notBefore, DateTime? expires, SecurityToken securityToken, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for TokenReplayValidator.
/// </summary>
/// <param name="expirationTime">The 'expiration' time found in the <see cref="SecurityToken"/>.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> being validated.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns></returns>
public delegate bool TokenReplayValidator(DateTime? expirationTime, string securityToken, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for SignatureValidator.
/// </summary>
/// <param name="token">A securityToken with a signature.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
public delegate SecurityToken SignatureValidator(string token, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for TokenReader.
/// </summary>
/// <param name="token">A securityToken with a signature.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
public delegate SecurityToken TokenReader(string token, TokenValidationParameters validationParameters);
/// <summary>
/// Definition for TokenDecryptionKeyResolver.
/// </summary>
/// <param name="token">The <see cref="string"/> representation of the token to be decrypted.</param>
/// <param name="securityToken">The <see cref="SecurityToken"/> to be decrypted. The runtime by default passes null.</param>
/// <param name="kid">A key identifier. It may be null.</param>
/// <param name="validationParameters"><see cref="TokenValidationParameters"/> required for validation.</param>
/// <returns>A <see cref="SecurityKey"/> to use when decrypting the token.</returns>
public delegate IEnumerable<SecurityKey> TokenDecryptionKeyResolver(string token, SecurityToken securityToken, string kid, TokenValidationParameters validationParameters);
/// <summary>
/// Contains a set of parameters that are used by a <see cref="SecurityTokenHandler"/> when validating a <see cref="SecurityToken"/>.
/// </summary>
public class TokenValidationParameters
{
private string _authenticationType;
private TimeSpan _clockSkew = DefaultClockSkew;
private string _nameClaimType = ClaimsIdentity.DefaultNameClaimType;
private string _roleClaimType = ClaimsIdentity.DefaultRoleClaimType;
/// <summary>
/// This is the fallback authenticationtype that a <see cref="ISecurityTokenValidator"/> will use if nothing is set.
/// </summary>
public static readonly string DefaultAuthenticationType = "AuthenticationTypes.Federation"; // Note: The change was because 5.x removed the dependency on System.IdentityModel and we used a different string which was a mistake.
/// <summary>
/// Default for the clock skew.
/// </summary>
/// <remarks>300 seconds (5 minutes).</remarks>
public static readonly TimeSpan DefaultClockSkew = TimeSpan.FromSeconds(300); // 5 min.
/// <summary>
/// Default for the maximm token size.
/// </summary>
/// <remarks>2 MB (mega bytes).</remarks>
public const Int32 DefaultMaximumTokenSizeInBytes = 1024 * 1024 * 2; // 2meg.
/// <summary>
/// Copy constructor for <see cref="TokenValidationParameters"/>.
/// </summary>
protected TokenValidationParameters(TokenValidationParameters other)
{
if (other == null)
{
throw LogHelper.LogExceptionMessage(new ArgumentNullException("other"));
}
ActorValidationParameters = other.ActorValidationParameters?.Clone();
AudienceValidator = other.AudienceValidator;
_authenticationType = other._authenticationType;
ClockSkew = other.ClockSkew;
CryptoProviderFactory = other.CryptoProviderFactory;
IssuerSigningKey = other.IssuerSigningKey;
IssuerSigningKeyResolver = other.IssuerSigningKeyResolver;
IssuerSigningKeys = other.IssuerSigningKeys;
IssuerSigningKeyValidator = other.IssuerSigningKeyValidator;
IssuerValidator = other.IssuerValidator;
LifetimeValidator = other.LifetimeValidator;
TokenReplayValidator = other.TokenReplayValidator;
NameClaimType = other.NameClaimType;
NameClaimTypeRetriever = other.NameClaimTypeRetriever;
PropertyBag = other.PropertyBag;
RequireExpirationTime = other.RequireExpirationTime;
RequireSignedTokens = other.RequireSignedTokens;
RoleClaimType = other.RoleClaimType;
RoleClaimTypeRetriever = other.RoleClaimTypeRetriever;
SaveSigninToken = other.SaveSigninToken;
SignatureValidator = other.SignatureValidator;
TokenDecryptionKey = other.TokenDecryptionKey;
TokenDecryptionKeyResolver = other.TokenDecryptionKeyResolver;
TokenDecryptionKeys = other.TokenDecryptionKeys;
TokenReader = other.TokenReader;
TokenReplayCache = other.TokenReplayCache;
ValidateActor = other.ValidateActor;
ValidateAudience = other.ValidateAudience;
ValidateIssuer = other.ValidateIssuer;
ValidateIssuerSigningKey = other.ValidateIssuerSigningKey;
ValidateLifetime = other.ValidateLifetime;
ValidateTokenReplay = other.ValidateTokenReplay;
ValidAudience = other.ValidAudience;
ValidAudiences = other.ValidAudiences;
ValidIssuer = other.ValidIssuer;
ValidIssuers = other.ValidIssuers;
}
/// <summary>
/// Initializes a new instance of the <see cref="TokenValidationParameters"/> class.
/// </summary>
public TokenValidationParameters()
{
RequireExpirationTime = true;
RequireSignedTokens = true;
SaveSigninToken = false;
ValidateActor = false;
ValidateAudience = true;
ValidateIssuer = true;
ValidateIssuerSigningKey = false;
ValidateLifetime = true;
ValidateTokenReplay = false;
}
/// <summary>
/// Gets or sets <see cref="TokenValidationParameters"/>.
/// </summary>
public TokenValidationParameters ActorValidationParameters
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to validate the audience.
/// </summary>
/// <remarks>
/// If set, this delegate will be called to validate the 'audience' instead of normal processing.
/// If <see cref="ValidateAudience"/> is false, this delegate will not be called.
/// </remarks>
public AudienceValidator AudienceValidator
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to read the token.
/// </summary>
/// <remarks>
/// If set, this delegate will be called to read the token instead of normal processing.
/// </remarks>
public TokenReader TokenReader
{
get;
set;
}
/// <summary>
/// Gets or sets the AuthenticationType when creating a <see cref="ClaimsIdentity"/>.
/// </summary>
/// <exception cref="ArgumentNullException">If 'value' is null or whitespace.</exception>
public string AuthenticationType
{
get
{
return _authenticationType;
}
set
{
if (string.IsNullOrWhiteSpace(value))
{
throw LogHelper.LogExceptionMessage(new ArgumentNullException("AuthenticationType"));
}
_authenticationType = value;
}
}
///// <summary>
///// Gets or sets the <see cref="X509CertificateValidator"/> for validating X509Certificate2(s).
///// </summary>
//public X509CertificateValidator CertificateValidator
//{
// get
// {
// return _certificateValidator;
// }
// set
// {
// _certificateValidator = value;
// }
//}
/// <summary>
/// Gets or sets the clock skew to apply when validating a time.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">If 'value' is less than 0.</exception>
[DefaultValue(300)]
public TimeSpan ClockSkew
{
get
{
return _clockSkew;
}
set
{
if (value < TimeSpan.Zero)
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException(nameof(value), LogHelper.FormatInvariant(LogMessages.IDX10100, value)));
_clockSkew = value;
}
}
/// <summary>
/// Returns a new instance of <see cref="TokenValidationParameters"/> with values copied from this object.
/// </summary>
/// <returns>A new <see cref="TokenValidationParameters"/> object copied from this object</returns>
/// <remarks>This is a shallow Clone.</remarks>
public virtual TokenValidationParameters Clone()
{
return new TokenValidationParameters(this);
}
/// <summary>
/// Creates a <see cref="ClaimsIdentity"/> using:
/// <para><see cref="AuthenticationType"/></para>
/// <para>'NameClaimType': If NameClaimTypeRetriever is set, call delegate, else call NameClaimType. If the result is a null or empty string, use <see cref="ClaimsIdentity.DefaultNameClaimType"/></para>.
/// <para>'RoleClaimType': If RoleClaimTypeRetriever is set, call delegate, else call RoleClaimType. If the result is a null or empty string, use <see cref="ClaimsIdentity.DefaultRoleClaimType"/></para>.
/// </summary>
/// <returns>A <see cref="ClaimsIdentity"/> with Authentication, NameClaimType and RoleClaimType set.</returns>
public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken, string issuer)
{
string nameClaimType = null;
if (NameClaimTypeRetriever != null)
{
nameClaimType = NameClaimTypeRetriever(securityToken, issuer);
}
else
{
nameClaimType = NameClaimType;
}
string roleClaimType = null;
if (RoleClaimTypeRetriever != null)
{
roleClaimType = RoleClaimTypeRetriever(securityToken, issuer);
}
else
{
roleClaimType = RoleClaimType;
}
LogHelper.LogInformation(LogMessages.IDX10245, securityToken);
return new ClaimsIdentity(authenticationType: AuthenticationType ?? DefaultAuthenticationType, nameType: nameClaimType ?? ClaimsIdentity.DefaultNameClaimType, roleType: roleClaimType ?? ClaimsIdentity.DefaultRoleClaimType);
}
/// <summary>
/// Users can override the default <see cref="CryptoProviderFactory"/> with this property. This factory will be used for creating signature providers.
/// </summary>
public CryptoProviderFactory CryptoProviderFactory
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="SecurityKey"/> that is to be used for decryption.
/// </summary>
public SecurityKey TokenDecryptionKey
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be called to retreive a <see cref="SecurityKey"/> used for decryption.
/// </summary>
/// <remarks>
/// This <see cref="SecurityKey"/> will be used to decrypt the token. This can be helpful when the <see cref="SecurityToken"/> does not contain a key identifier.
/// </remarks>
public TokenDecryptionKeyResolver TokenDecryptionKeyResolver
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate for validating the <see cref="SecurityKey"/> that signed the token.
/// </summary>
/// <remarks>
/// If set, this delegate will be called to validate the <see cref="SecurityKey"/> that signed the token, instead of normal processing.
/// </remarks>
public IssuerSigningKeyValidator IssuerSigningKeyValidator
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="SecurityKey"/> that is to be used for signature validation.
/// </summary>
public SecurityKey IssuerSigningKey
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be called to retrieve a <see cref="SecurityKey"/> used for signature validation.
/// </summary>
/// <remarks>
/// This <see cref="SecurityKey"/> will be used to check the signature. This can be helpful when the <see cref="SecurityToken"/> does not contain a key identifier.
/// </remarks>
public IssuerSigningKeyResolver IssuerSigningKeyResolver
{
get;
set;
}
/// <summary>
/// Gets or sets an <see cref="IEnumerable{SecurityKey}"/> used for signature validation.
/// </summary>
public IEnumerable<SecurityKey> IssuerSigningKeys
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to validate the issuer of the token.
/// </summary>
/// <remarks>
/// If set, this delegate will be called to validate the 'issuer' of the token, instead of normal processing.
/// If <see cref="ValidateIssuer"/> is false, this delegate will not be called.
/// </remarks>
public IssuerValidator IssuerValidator
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to validate the lifetime of the token
/// </summary>
/// <remarks>
/// If set, this delegate will be called to validate the lifetime of the token, instead of normal processing.
/// If <see cref="ValidateLifetime"/> is false, this delegate will not be called.
/// </remarks>
public LifetimeValidator LifetimeValidator
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to validate the token replay of the token
/// </summary>
/// <remarks>
/// If set, this delegate will be called to validate the token replay of the token, instead of normal processing.
/// If <see cref="ValidateTokenReplay"/> is false, this delegate will not be called.
/// </remarks>
public TokenReplayValidator TokenReplayValidator
{
get;
set;
}
/// <summary>
/// Gets or sets a <see cref="string"/> that defines the <see cref="ClaimsIdentity.NameClaimType"/>.
/// </summary>
/// <remarks>
/// Controls the value <see cref="ClaimsIdentity.Name"/> returns. It will return the first <see cref="Claim.Value"/> where the <see cref="Claim.Type"/> equals <see cref="NameClaimType"/>.
/// </remarks>
public string NameClaimType
{
get
{
return _nameClaimType;
}
set
{
if (string.IsNullOrWhiteSpace(value))
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException("value", LogMessages.IDX10102));
_nameClaimType = value;
}
}
/// <summary>
/// Gets or sets the <see cref="string"/> that defines the <see cref="ClaimsIdentity.RoleClaimType"/>.
/// </summary>
/// <remarks>
/// <para>Controls the results of <see cref="ClaimsPrincipal.IsInRole( string )"/>.</para>
/// <para>Each <see cref="Claim"/> where <see cref="Claim.Type"/> == <see cref="RoleClaimType"/> will be checked for a match against the 'string' passed to <see cref="ClaimsPrincipal.IsInRole(string)"/>.</para>
/// </remarks>
public string RoleClaimType
{
get
{
return _roleClaimType;
}
set
{
if (string.IsNullOrWhiteSpace(value))
throw LogHelper.LogExceptionMessage(new ArgumentOutOfRangeException("value", LogMessages.IDX10103));
_roleClaimType = value;
}
}
/// <summary>
/// Gets or sets a delegate that will be called to obtain the NameClaimType to use when creating a ClaimsIdentity
/// after validating a token.
/// </summary>
public Func<SecurityToken, string, string> NameClaimTypeRetriever { get; set; }
/// <summary>
/// Gets or sets the <see cref="IDictionary{String, Object}"/> that contains a collection of custom key/value pairs. This allows addition of parameters that could be used in custom token validation scenarios.
/// </summary>
public IDictionary<string, Object> PropertyBag
{
get;
set;
}
/// <summary>
/// Gets or sets a value indicating whether tokens must have an 'expiration' value.
/// </summary>
[DefaultValue(true)]
public bool RequireExpirationTime { get; set; }
/// <summary>
/// Gets or sets a value indicating whether a <see cref="SecurityToken"/> can be considered valid if not signed.
/// </summary>
[DefaultValue(true)]
public bool RequireSignedTokens { get; set; }
/// <summary>
/// Gets or sets a delegate that will be called to obtain the RoleClaimType to use when creating a ClaimsIdentity
/// after validating a token.
/// </summary>
public Func<SecurityToken, string, string> RoleClaimTypeRetriever { get; set; }
/// <summary>
/// Gets or sets a boolean to control if the original token should be saved after the security token is validated.
/// </summary>
/// <remarks>The runtime will consult this value and save the original token that was validated.</remarks>
[DefaultValue(false)]
public bool SaveSigninToken
{
get;
set;
}
/// <summary>
/// Gets or sets a delegate that will be used to validate the signature of the token.
/// </summary>
/// <remarks>
/// If set, this delegate will be called to signature of the token, instead of normal processing.
/// </remarks>
public SignatureValidator SignatureValidator
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="IEnumerable{SecurityKey}"/> that is to be used for decrypting inbound tokens.
/// </summary>
public IEnumerable<SecurityKey> TokenDecryptionKeys
{
get;
set;
}
/// <summary>
/// Gets or set the <see cref="ITokenReplayCache"/> that store tokens that can be checked to help detect token replay.
/// </summary>
/// <remarks>If set, then tokens must have an expiration time or the runtime will fault.</remarks>
public ITokenReplayCache TokenReplayCache
{
get;
set;
}
/// <summary>
/// Gets or sets a value indicating if an actor token is detected, whether it should be validated.
/// </summary>
[DefaultValue(false)]
public bool ValidateActor
{
get;
set;
}
/// <summary>
/// Gets or sets a boolean to control if the audience will be validated during token validation.
/// </summary>
/// <remarks>Validation of the audience, mitigates forwarding attacks. For example, a site that receives a token, could not replay it to another side.
/// A forwarded token would contain the audience of the original site.</remarks>
[DefaultValue(true)]
public bool ValidateAudience
{
get;
set;
}
/// <summary>
/// Gets or sets a boolean to control if the issuer will be validated during token validation.
/// </summary>
/// <remarks>
/// Validation of the issuer mitigates forwarding attacks that can occur when an
/// IdentityProvider represents multiple tenants and signs tokens with the same keys.
/// It is possible that a token issued for the same audience could be from a different tenant. For example an application could accept users from
/// contoso.onmicrosoft.com but not fabrikam.onmicrosoft.com, both valid tenants. A application that accepts tokens from fabrikam could forward them
/// to the application that accepts tokens for contoso.
/// </remarks>
[DefaultValue(true)]
public bool ValidateIssuer
{
get;
set;
}
/// <summary>
/// Gets or sets a boolean to control if the lifetime will be validated during token validation.
/// </summary>
[DefaultValue(true)]
public bool ValidateLifetime
{
get;
set;
}
/// <summary>
/// Gets or sets a boolean that controls if validation of the <see cref="SecurityKey"/> that signed the securityToken is called.
/// </summary>
/// <remarks>It is possible for tokens to contain the public key needed to check the signature. For example, X509Data can be hydrated into an X509Certificate,
/// which can be used to validate the signature. In these cases it is important to validate the SigningKey that was used to validate the signature. </remarks>
[DefaultValue(false)]
public bool ValidateIssuerSigningKey
{
get;
set;
}
/// <summary>
/// Gets or sets a boolean to control if the token replay will be validated during token validation.
/// </summary>
[DefaultValue(false)]
public bool ValidateTokenReplay
{
get;
set;
}
/// <summary>
/// Gets or sets a string that represents a valid audience that will be used to check against the token's audience.
/// </summary>
public string ValidAudience
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="IEnumerable{String}"/> that contains valid audiences that will be used to check against the token's audience.
/// </summary>
public IEnumerable<string> ValidAudiences
{
get;
set;
}
/// <summary>
/// Gets or sets a <see cref="String"/> that represents a valid issuer that will be used to check against the token's issuer.
/// </summary>
public string ValidIssuer
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="IEnumerable{String}"/> that contains valid issuers that will be used to check against the token's issuer.
/// </summary>
public IEnumerable<string> ValidIssuers
{
get;
set;
}
}
}