// 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.Diagnostics.CodeAnalysis; using System.IdentityModel.Tokens.Jwt; using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Tokens; namespace Microsoft.AspNet.Builder { /// /// Configuration options for /// public class OpenIdConnectOptions : RemoteAuthenticationOptions { /// /// Initializes a new /// public OpenIdConnectOptions() : this(OpenIdConnectDefaults.AuthenticationScheme) { } /// /// Initializes a new /// /// /// Defaults: /// AddNonceToRequest: true. /// BackchannelTimeout: 1 minute. /// Caption: . /// ProtocolValidator: new . /// RefreshOnIssuerKeyNotFound: true /// ResponseType: /// Scope: . /// TokenValidationParameters: new with AuthenticationScheme = authenticationScheme. /// UseTokenLifetime: false. /// /// will be used to when creating the for the AuthenticationScheme property. [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectOptions.set_Caption(System.String)", Justification = "Not a LOC field")] public OpenIdConnectOptions(string authenticationScheme) { AuthenticationScheme = authenticationScheme; DisplayName = OpenIdConnectDefaults.Caption; CallbackPath = new PathString("/signin-oidc"); Events = new OpenIdConnectEvents(); } /// /// Gets or sets the expected audience for any received JWT token. /// /// /// The expected audience for any received JWT token. /// public string Audience { get; set; } /// /// Gets or sets the Authority to use when making OpenIdConnect calls. /// public string Authority { get; set; } /// /// Gets or sets the 'client_id'. /// public string ClientId { get; set; } /// /// Gets or sets the 'client_secret'. /// public string ClientSecret { get; set; } /// /// 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; } /// /// Boolean to set whether the middleware should go to user info endpoint to retrieve additional claims or not after creating an identity from id_token received from token endpoint. /// public bool GetClaimsFromUserInfoEndpoint { get; set; } /// /// Gets or sets if HTTPS is required for the metadata address or authority. /// The default is true. This should be disabled only in development environments. /// public bool RequireHttpsMetadata { get; set; } = true; /// /// Gets or sets the discovery endpoint for obtaining metadata /// public string MetadataAddress { get; set; } /// /// Gets or sets the to notify when processing OpenIdConnect messages. /// public new IOpenIdConnectEvents Events { get { return (IOpenIdConnectEvents)base.Events; } set { base.Events = value; } } /// /// Gets or sets the that is used to ensure that the 'id_token' received /// is valid per: http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation /// /// if 'value' is null. public OpenIdConnectProtocolValidator ProtocolValidator { get; set; } = new OpenIdConnectProtocolValidator() { RequireStateValidation = false, NonceLifetime = TimeSpan.FromMinutes(15) }; /// /// Gets or sets the 'post_logout_redirect_uri' /// /// This is sent to the OP as the redirect for the user-agent. [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "By design")] [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Logout", Justification = "This is the term used in the spec.")] public string PostLogoutRedirectUri { 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; /// /// Gets or sets the method used to redirect the user agent to the identity provider. /// public OpenIdConnectRedirectBehavior AuthenticationMethod { get; set; } /// /// Gets or sets the 'resource'. /// public string Resource { get; set; } /// /// Gets or sets the 'response_mode'. /// public string ResponseMode { get; set; } = OpenIdConnectResponseModes.FormPost; /// /// Gets or sets the 'response_type'. /// public string ResponseType { get; set; } = OpenIdConnectResponseTypes.CodeIdToken; /// /// Gets the list of permissions to request. /// public IList Scope { get; } = new List { "openid", "profile" }; /// /// Gets or sets the type used to secure data handled by the middleware. /// public ISecureDataFormat StateDataFormat { get; set; } /// /// Gets or sets the type used to secure strings used by the middleware. /// public ISecureDataFormat StringDataFormat { get; set; } /// /// Gets or sets the used to validate identity tokens. /// public ISecurityTokenValidator SecurityTokenValidator { get; set; } = new JwtSecurityTokenHandler(); /// /// Gets or sets the parameters used to validate identity tokens. /// /// Contains the types and definitions required for validating a token. public TokenValidationParameters TokenValidationParameters { get; set; } = new TokenValidationParameters(); /// /// Indicates that the authentication session lifetime (e.g. cookies) should match that of the authentication token. /// If the token does not provide lifetime information then normal session lifetimes will be used. /// This is disabled by default. /// public bool UseTokenLifetime { get; set; } } }