Share via


JwtSecurityTokenHandler.ValidateAudience Method (JwtSecurityToken, TokenValidationParameters)

Validates that Audience is an expected value.

Namespace:  System.IdentityModel.Tokens
Assembly:  System.IdentityModel.Tokens.Jwt (in System.IdentityModel.Tokens.Jwt.dll)

Syntax

'Declaration
Protected Overridable Sub ValidateAudience ( _
    jwt As JwtSecurityToken, _
    validationParameters As TokenValidationParameters _
)
protected virtual void ValidateAudience(
    JwtSecurityToken jwt,
    TokenValidationParameters validationParameters
)
protected:
virtual void ValidateAudience(
    JwtSecurityToken^ jwt, 
    TokenValidationParameters^ validationParameters
)
abstract ValidateAudience : 
        jwt:JwtSecurityToken * 
        validationParameters:TokenValidationParameters -> unit  
override ValidateAudience : 
        jwt:JwtSecurityToken * 
        validationParameters:TokenValidationParameters -> unit
protected function ValidateAudience(
    jwt : JwtSecurityToken, 
    validationParameters : TokenValidationParameters
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

'jwt' is null.

-or-

'validationParameters' is null.

SecurityTokenValidationException

if IsNullOrWhiteSpace( Audience ) is true.

ArgumentException

'AllowedAudience' is null or whitespace AND AllowedAudiences is null.

AudienceUriValidationFailedException

Audience fails to match AllowedAudience or one of AllowedAudiences.

Remarks

If AudienceMode == Never OR( AudienceUriMode == BearerKeyOnly AND SecurityKeys.Count == 0 )then validation is skipped.

If validation is performed, Audience is compared first to AllowedAudience and then to each string in AllowedAudiences. Returns when first compare succeeds. Compare is performed using StringComparison.Ordinal (case sensitive).

.NET Framework Security

See Also

Reference

JwtSecurityTokenHandler Class

ValidateAudience Overload

System.IdentityModel.Tokens Namespace