// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Net.Http; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.JwtBearer { /// /// Options class provides information needed to control Bearer Authentication middleware behavior /// public class JwtBearerAuthenticationOptions : AuthenticationOptions { /// /// Creates an instance of bearer authentication options with default values. /// public JwtBearerAuthenticationOptions() : base() { AuthenticationScheme = JwtBearerAuthenticationDefaults.AuthenticationScheme; } /// /// Gets or sets the discovery endpoint for obtaining metadata /// public string MetadataAddress { get; set; } /// /// Gets or sets the Authority to use when making OpenIdConnect calls. /// public string Authority { get; set; } /// /// Gets or sets the audience for any received JWT token. /// /// /// The expected audience for any received JWT token. /// public string Audience { get; set; } /// /// Gets or sets the challenge to put in the "WWW-Authenticate" header. /// public string Challenge { get; set; } = JwtBearerAuthenticationDefaults.AuthenticationScheme; /// /// The object provided by the application to process events raised by the bearer authentication middleware. /// The application may implement the interface fully, or it may create an instance of JwtBearerAuthenticationProvider /// and assign delegates only to the events it wants to process. /// public JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications(); /// /// The HttpMessageHandler used to retrieve metadata. /// This cannot be set at the same time as BackchannelCertificateValidator unless the value /// is a WebRequestHandler. /// public HttpMessageHandler BackchannelHttpHandler { get; set; } /// /// Gets or sets the timeout when using the backchannel to make an http call. /// public TimeSpan BackchannelTimeout { get; set; } = TimeSpan.FromMinutes(1); #if DNX451 /// /// Gets or sets the a pinned certificate validator to use to validate the endpoints used /// when retrieving metadata. /// /// /// The pinned certificate validator. /// /// If this property is null then the default certificate checks are performed, /// validating the subject name and if the signing chain is a trusted party. public ICertificateValidator BackchannelCertificateValidator { get; set; } #endif /// /// Configuration provided directly by the developer. If provided, then MetadataAddress and the Backchannel properties /// will not be used. This information should not be updated during request processing. /// public OpenIdConnectConfiguration Configuration { get; set; } /// /// Responsible for retrieving, caching, and refreshing the configuration from metadata. /// If not provided, then one will be created using the MetadataAddress and Backchannel properties. /// public IConfigurationManager ConfigurationManager { get; set; } /// /// Gets or sets if a metadata refresh should be attempted after a SecurityTokenSignatureKeyNotFoundException. This allows for automatic /// recovery in the event of a signature key rollover. This is enabled by default. /// public bool RefreshOnIssuerKeyNotFound { get; set; } = true; /// /// Used to know what the current clock time is when calculating or validating token expiration. When not assigned default is based on /// DateTimeOffset.UtcNow. This is typically needed only for unit testing. /// public ISystemClock SystemClock { get; set; } = new SystemClock(); /// /// Gets the ordered list of used to validate access tokens. /// public IList SecurityTokenValidators { get; } = new List { new JwtSecurityTokenHandler() }; /// /// Gets or sets the parameters used to validate identity tokens. /// /// Contains the types and definitions required for validating a token. /// if 'value' is null. public TokenValidationParameters TokenValidationParameters { get; set; } = new TokenValidationParameters(); } }