Profile Service
Duende.IdentityServer.Services.IProfileService
Section titled “Duende.IdentityServer.Services.IProfileService”Encapsulates retrieval of user claims from a data source of your choice. See here for a sample.
Two first-party implementations are available: the ASP.NET Identity integration and the Duende User Management integration. You can also write your own implementation.
/// <summary>/// This interface allows IdentityServer to connect to your user and profile store./// </summary>public interface IProfileService{ /// <summary> /// This method is called whenever claims about the user are requested (e.g. during token creation or via the userinfo endpoint) /// </summary> /// <param name="context">The context.</param> /// <param name="ct">The cancellation token.</param> /// <returns></returns> Task GetProfileDataAsync(ProfileDataRequestContext context, CancellationToken ct);
/// <summary> /// This method gets called whenever identity server needs to determine if the user is valid or active (e.g. if the user's account has been deactivated since they logged in). /// (e.g. during token issuance or validation). /// </summary> /// <param name="context">The context.</param> /// <returns></returns> Task IsActiveAsync(IsActiveContext context, CancellationToken ct);}-
GetProfileDataAsyncThe API that is expected to load claims for a user. It is passed an instance of
ProfileDataRequestContext. -
IsActiveAsyncThe API that is expected to indicate if a user is currently allowed to obtain tokens. It is passed an instance of
IsActiveContext.
Duende.IdentityServer.Models.ProfileDataRequestContext
Section titled “Duende.IdentityServer.Models.ProfileDataRequestContext”Models the request for user claims and is the vehicle to return those claims. It contains these properties:
-
SubjectThe
ClaimsPrincipalmodeling the user associated with this request for profile data. When the profile service is invoked for tokens, theSubjectproperty will contain the user’s principal. Which claims are contained in the principal depends on the following:- When the server side sessions feature is enabled
Subjectwill always contain the claims stored in the server side session. - When that is not the case, it depends on the caller context:
- If the
ProfileServiceis called in the context of a grant (e.g. exchanging a code for a token), the claims associated with that grant in the grant store will be used. When grants are stored, by default a snapshot of the logged-in user’s claims are captured with the grant. - If there’s no grant context (e.g. when the user info endpoint is called) the claims in the access token will be used.
- If the
- When the server side sessions feature is enabled
-
ClientThe
Clientfor which the claims are being requested. -
RequestedClaimTypesThe collection of claim types being requested. This data is source from the requested scopes and their associated claim types.
-
CallerAn identifier for the context in which the claims are being requested (e.g. an identity token, an access token, or the user info endpoint). The
IdentityServerConstants.ProfileDataCallersclass contains the different constant values. -
IssuedClaimsThe list of claims that will be returned. This is expected to be populated by the custom
IProfileServiceimplementation. -
SamlAttributesA list of
SamlAttributeobjects to include directly in SAML assertions, bypassing the standard claim-to-attribute mapping. Use this when you need full control over the SAML attribute name, format, or values.Any claims added to
IssuedClaimsare also carried over to the assertion by running through the claim mapping translation layer. -
AddRequestedClaimsExtension method on the
ProfileDataRequestContextto populate theIssuedClaims, but first filters the claims based onRequestedClaimTypes.
Duende.IdentityServer.Models.IsActiveContext
Section titled “Duende.IdentityServer.Models.IsActiveContext”Models the request to determine if the user is currently allowed to obtain tokens. It contains these properties:
-
SubjectThe
ClaimsPrincipalmodeling the user. -
ClientThe
Clientfor which the claims are being requested. -
CallerAn identifier for the context in which the claims are being requested. The constant
IdentityServerConstants.ProfileIsActiveCallerscontains the possible values:Constant When it is used AuthorizeEndpointDuring an authorize request (interactive login) AuthorizationCodeValidationWhen an authorization code is exchanged for tokens AccessTokenValidationWhen an access token is validated (e.g. at the introspection endpoint) IdentityTokenValidationWhen an identity token is validated ResourceOwnerValidationDuring a resource owner password grant ExtensionGrantValidationDuring an extension grant RefreshTokenValidationWhen a refresh token is used UserInfoRequestValidationWhen the user info endpoint is called DeviceCodeValidationWhen a device code is polled BackchannelAuthenticationRequestIdValidationWhen a CIBA request is polled SamlSsoEndpointDuring a SAML SSO request :badge[v8.0] -
IsActiveThe flag indicating if the user is allowed to obtain tokens. This is expected to be assigned by the custom
IProfileServiceimplementation.