Dependency Injection Extension Methods
AddIdentityServer return a builder object that provides many extension methods to add IdentityServer specific services
to the ASP.NET Core service provider. Here’s a list grouped by feature areas.
var idsvrBuilder = builder.Services.AddIdentityServer();Configuration Stores
Section titled “Configuration Stores”Several convenience methods are provided for registering custom stores:
-
AddClientStore<T>Registers a custom
IClientStoreimplementation. -
AddCorsPolicyService<T>Registers a custom
ICorsPolicyServiceimplementation. -
AddResourceStore<T>Registers a custom
IResourceStoreimplementation. -
AddIdentityProviderStore<T>Registers a custom
IIdentityProviderStoreimplementation.
The in-memory configuration stores can be registered in DI with the following extension methods.
-
AddInMemoryClientsRegisters
IClientStoreandICorsPolicyServiceimplementations based on the in-memory collection ofClientconfiguration objects. -
AddInMemoryIdentityResourcesRegisters
IResourceStoreimplementation based on the in-memory collection ofIdentityResourceconfiguration objects. -
AddInMemoryApiScopesRegisters
IResourceStoreimplementation based on the in-memory collection ofApiScopeconfiguration objects. -
AddInMemoryApiResourcesRegisters
IResourceStoreimplementation based on the in-memory collection ofApiResourceconfiguration objects.
Caching Configuration Data
Section titled “Caching Configuration Data”Extension methods to enable caching for configuration data:
-
AddInMemoryCaching<T>To use any of the caches described below, an implementation of
ICache<T>must be registered in the ASP.NET Core service provider. This API registers a default in-memory implementation ofICache<T>that’s based on ASP.NET Core’sMemoryCache. -
AddClientStoreCache<T>Registers aIClientStoredecorator implementation which will maintain an in-memory cache ofClientconfiguration objects. The cache duration is configurable on theCachingconfiguration options on theIdentityServerOptions. -
AddResourceStoreCache<T>Registers a
IResourceStoredecorator implementation which will maintain an in-memory cache ofIdentityResourceandApiResourceconfiguration objects. The cache duration is configurable on theCachingconfiguration options on theIdentityServerOptions. -
AddCorsPolicyCache<T>Registers a
ICorsPolicyServicedecorator implementation which will maintain an in-memory cache of the results of the CORS policy service evaluation. The cache duration is configurable on theCachingconfiguration options on theIdentityServerOptions. -
AddIdentityProviderStoreCache<T>Registers a
IIdentityProviderStoredecorator implementation which will maintain an in-memory cache ofIdentityProviderconfiguration objects. The cache duration is configurable on theCachingconfiguration options on theIdentityServerOptions.
Test Stores
Section titled “Test Stores”The TestUser class models a user, their credentials, and claims in IdentityServer.
Use of TestUser is similar to the use of the “in-memory” stores in that it is intended for when prototyping,
developing, and/or testing.
The use of TestUser is not recommended in production.
-
AddTestUsersRegisters
TestUserStorebased on a collection ofTestUserobjects.TestUserStoreis e.g. used by the default quickstart UI. Also registers implementations ofIProfileServiceandIResourceOwnerPasswordValidatorthat uses the test users as a backing store.
Signing keys
Section titled “Signing keys”Duende IdentityServer needs key material to sign tokens. This key material can either be created and managed automatically or configured statically.
Duende IdentityServer supports X.509 certificates (both raw files and a reference to the certificate store), RSA keys and EC keys for token signatures and validation. Each key can be configured with a (compatible) signing algorithm, e.g. RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 or ES512.
You can configure the key material with the following methods:
-
AddSigningCredentialAdds a signing key that provides the specified key material to the various token creation/validation services.
-
AddDeveloperSigningCredentialCreates temporary key material at startup time. This is for dev scenarios. The generated key will be persisted in the local directory by default (or just kept in memory).
-
AddValidationKeyAdds a key for validating tokens. They will be used by the internal token validator and will show up in the discovery document.
Additional services
Section titled “Additional services”The following are convenient to add additional features to your IdentityServer.
-
AddExtensionGrantValidatorAdds an
IExtensionGrantValidatorimplementation for use with extension grants. -
AddSecretParserAdds an
ISecretParserimplementation for parsing client or API resource credentials. -
AddSecretValidatorAdds an
ISecretValidatorimplementation for validating client or API resource credentials against a credential store. -
AddResourceOwnerValidatorAdds an
IResourceOwnerPasswordValidatorimplementation for validating user credentials for the resource owner password credentials grant type. -
AddProfileServiceAdds an
IProfileServiceimplementation. The default implementation (found inDefaultProfileService) relies upon the authentication cookie as the only source of claims for issuing in tokens. -
AddAuthorizeInteractionResponseGeneratorAdds an
IAuthorizeInteractionResponseGeneratorimplementation to customize logic at authorization endpoint for when a user must be shown a UI for error, login, consent, or any other custom page. The default implementation can be found in theAuthorizeInteractionResponseGeneratorclass, so consider deriving from this existing class if you need to augment the existing behavior. -
AddCustomAuthorizeRequestValidatorAdds an
ICustomAuthorizeRequestValidatorimplementation to customize request parameter validation at the authorization endpoint. -
AddCustomTokenRequestValidatorAdds an
ICustomTokenRequestValidatorimplementation to customize request parameter validation at the token endpoint. -
AddRedirectUriValidatorAdds an
IRedirectUriValidatorimplementation to customize redirect URI validation. -
AddAppAuthRedirectUriValidatorAdds an “AppAuth” (OAuth 2.0 for Native Apps) compliant redirect URI validator (does strict validation but also allows
http://127.0.0.1with random port). -
AddJwtBearerClientAuthenticationAdds support for client authentication using JWT bearer assertions.
-
AddMutualTlsSecretValidatorsAdds the X509 secret validators for mutual TLS.
-
AddIdentityProviderConfigurationValidatorAdds an IdentityProvider configuration validator.
-
AddBackchannelAuthenticationUserValidatorAdds the backchannel login user validator.
-
AddBackchannelAuthenticationUserNotificationServiceAdds the backchannel login user validator.