/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/openiddict/openiddict-core for more information concerning * the license and the contributors participating to this project. */ using System.ComponentModel; using System.Security.Claims; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Tokens; namespace OpenIddict.Client; /// /// Provides various settings needed to configure the OpenIddict client handler. /// public sealed class OpenIddictClientOptions { /// /// Gets or sets the optional URI used to uniquely identify the client/relying party. /// The URI must be absolute and may contain a path, but no query string or fragment part. /// public Uri? ClientUri { get; set; } /// /// Gets the list of the handlers responsible for processing the OpenIddict client operations. /// Note: the list is automatically sorted based on the order assigned to each handler descriptor. /// As such, it MUST NOT be mutated after options initialization to preserve the exact order. /// public List Handlers { get; } = new(DefaultHandlers); /// /// Gets the list of encryption credentials used by the OpenIddict client services. /// Multiple credentials can be added to support key rollover, but if X.509 keys /// are used, at least one of them must have a valid creation/expiration date. /// Note: the encryption credentials are not used to protect/unprotect tokens issued /// by ASP.NET Core Data Protection, that uses its own key ring, configured separately. /// /// /// Note: OpenIddict automatically sorts the credentials based on the following algorithm: /// /// Symmetric keys are always preferred when they can be used for the operation (e.g token encryption). /// X.509 keys are always preferred to non-X.509 asymmetric keys. /// X.509 keys with the furthest expiration date are preferred. /// X.509 keys whose backing certificate is not yet valid are never preferred. /// /// public List EncryptionCredentials { get; } = []; /// /// Gets the list of signing credentials used by the OpenIddict client services. /// Multiple credentials can be added to support key rollover, but if X.509 keys /// are used, at least one of them must have a valid creation/expiration date. /// Note: the signing credentials are not used to protect/unprotect tokens issued /// by ASP.NET Core Data Protection, that uses its own key ring, configured separately. /// /// /// Note: OpenIddict automatically sorts the credentials based on the following algorithm: /// /// Symmetric keys are always preferred when they can be used for the operation (e.g token signing). /// X.509 keys are always preferred to non-X.509 asymmetric keys. /// X.509 keys with the furthest expiration date are preferred. /// X.509 keys whose backing certificate is not yet valid are never preferred. /// /// public List SigningCredentials { get; } = []; /// /// Gets or sets the period of time client assertions remain valid after being issued. The default value is 5 minutes. /// While not recommended, this property can be set to to issue client assertions that never expire. /// public TimeSpan? ClientAssertionLifetime { get; set; } = TimeSpan.FromMinutes(5); /// /// Gets or sets the period of time state tokens remain valid after being issued. The default value is 15 minutes. /// While not recommended, this property can be set to to issue state tokens that never expire. /// public TimeSpan? StateTokenLifetime { get; set; } = TimeSpan.FromMinutes(15); /// /// Gets or sets the security token handler used to protect and unprotect tokens. /// public JsonWebTokenHandler JsonWebTokenHandler { get; set; } = new JsonWebTokenHandler { SetDefaultTimesOnTokenCreation = false }; /// /// Gets the absolute and relative URIs associated to the redirection endpoint. /// public List RedirectionEndpointUris { get; } = []; /// /// Gets the absolute and relative URIs associated to the post-logout redirection endpoint. /// public List PostLogoutRedirectionEndpointUris { get; } = []; /// /// Gets the static client registrations used by the OpenIddict client services. /// public List Registrations { get; } = []; /// /// Gets the token validation parameters used by the OpenIddict client services. /// /// /// This instance is not used to validate tokens issued by remote authorization servers /// and is only used with tokens produced and validated by the client itself (e.g state tokens). /// public TokenValidationParameters TokenValidationParameters { get; } = new() { AuthenticationType = TokenValidationParameters.DefaultAuthenticationType, ClockSkew = TimeSpan.Zero, NameClaimType = Claims.Name, RoleClaimType = Claims.Role, // Note: audience and lifetime are manually validated by OpenIddict itself. ValidateAudience = false, ValidateLifetime = false }; /// /// Gets or sets a boolean indicating whether token storage should be disabled. /// When disabled, no database entry is created for the tokens created by the /// OpenIddict client services. Using this option is generally NOT recommended. /// public bool DisableTokenStorage { get; set; } /// /// Gets or sets a boolean indicating whether the claim mapping feature inferring /// WS-Federation claims (exposed by the class) from their /// OpenID Connect/JSON Web Token or provider-specific equivalent should be disabled. /// /// /// Note: if automatic claim mapping is disabled, no WS-Federation claim will /// be added to . /// public bool DisableWebServicesFederationClaimMapping { get; set; } /// /// Gets the OAuth 2.0 code challenge methods enabled for this application. /// public HashSet CodeChallengeMethods { get; } = new(StringComparer.Ordinal); /// /// Gets the OAuth 2.0/OpenID Connect flows enabled for this application. /// public HashSet GrantTypes { get; } = new(StringComparer.Ordinal); /// /// Gets the OAuth 2.0/OpenID Connect response modes enabled for this application. /// [EditorBrowsable(EditorBrowsableState.Advanced)] public HashSet ResponseModes { get; } = new(StringComparer.Ordinal); /// /// Gets the OAuth 2.0/OpenID Connect response types enabled for this application. /// [EditorBrowsable(EditorBrowsableState.Advanced)] public HashSet ResponseTypes { get; } = new(StringComparer.Ordinal); #if SUPPORTS_TIME_PROVIDER /// /// Gets or sets the time provider. /// public TimeProvider? TimeProvider { get; set; } #endif }