Class ProfileService<TUser>
- Namespace
- Fdyay.IdentityServer.AspNetIdentity
- Assembly
- Fdyay.IdentityServer.AspNetIdentity.dll
Issues a user's claims, and answers whether the user is active, from ASP.NET Core Identity.
public class ProfileService<TUser> : IProfileService where TUser : class
Type Parameters
TUser
- Inheritance
-
ProfileService<TUser>
- Implements
- Inherited Members
Remarks
Duende 8.0.1's ProfileService<TUser>, measured: the user is found by its sub through
FindByIdAsync(string), its claims are what Identity's IUserClaimsPrincipalFactory<TUser>
makes — with AddAspNetIdentity, decorated to carry sub, name, preferred_username and the
verified flags — and only the requested ones are issued. A user Identity cannot find is inactive. Every step is
protected virtual, so a host deriving from this class changes one without rewriting the rest; the usual one
is IsUserActiveAsync(TUser), which says yes to every user that exists.
Constructors
ProfileService(UserManager<TUser>, IUserClaimsPrincipalFactory<TUser>)
Creates the service without a logger: a subject with no user goes unreported.
public ProfileService(UserManager<TUser> userManager, IUserClaimsPrincipalFactory<TUser> claimsFactory)
Parameters
userManagerUserManager<TUser>Finds the user by subject id.
claimsFactoryIUserClaimsPrincipalFactory<TUser>Makes the user's claims.
ProfileService(UserManager<TUser>, IUserClaimsPrincipalFactory<TUser>, ILogger<ProfileService<TUser>>)
Creates the service, as the container resolves it.
public ProfileService(UserManager<TUser> userManager, IUserClaimsPrincipalFactory<TUser> claimsFactory, ILogger<ProfileService<TUser>> logger)
Parameters
userManagerUserManager<TUser>Finds the user by subject id.
claimsFactoryIUserClaimsPrincipalFactory<TUser>Makes the user's claims.
loggerILogger<ProfileService<TUser>>Where a subject with no user is reported, as a warning.
Properties
ClaimsFactory
Makes the user's claims.
protected IUserClaimsPrincipalFactory<TUser> ClaimsFactory { get; }
Property Value
- IUserClaimsPrincipalFactory<TUser>
Logger
Where a subject with no user is reported. Null when constructed without one.
protected ILogger<ProfileService<TUser>>? Logger { get; }
Property Value
- ILogger<ProfileService<TUser>>
UserManager
Finds the user.
protected UserManager<TUser> UserManager { get; }
Property Value
- UserManager<TUser>
Methods
FindUserAsync(string)
The user with this subject id, or null — logged as a warning.
protected virtual Task<TUser?> FindUserAsync(string subjectId)
Parameters
subjectIdstring
Returns
- Task<TUser>
GetProfileDataAsync(ProfileDataRequestContext, string)
Issues the claims of the user with this subject id, if there is one.
protected virtual Task GetProfileDataAsync(ProfileDataRequestContext context, string subjectId)
Parameters
contextProfileDataRequestContextsubjectIdstring
Returns
GetProfileDataAsync(ProfileDataRequestContext, CancellationToken)
Adds the requested claims to IssuedClaims.
public virtual Task GetProfileDataAsync(ProfileDataRequestContext context, CancellationToken cancellationToken = default)
Parameters
contextProfileDataRequestContextcancellationTokenCancellationToken
Returns
Remarks
Issues the requested ones of the claims ClaimsFactory makes for the user; nothing when there is no such user.
Exceptions
- ArgumentNullException
contextis null.- InvalidOperationException
The subject is null or carries no
subclaim, or the claims factory made no principal.
GetProfileDataAsync(ProfileDataRequestContext, TUser)
Issues the requested ones of this user's claims.
protected virtual Task GetProfileDataAsync(ProfileDataRequestContext context, TUser user)
Parameters
contextProfileDataRequestContextuserTUser
Returns
GetUserClaimsAsync(TUser)
The user's claims, as ClaimsFactory makes them.
protected virtual Task<ClaimsPrincipal> GetUserClaimsAsync(TUser user)
Parameters
userTUser
Returns
IsActiveAsync(IsActiveContext, string)
Whether the user with this subject id is active: not, when there is no such user.
protected virtual Task IsActiveAsync(IsActiveContext context, string subjectId)
Parameters
contextIsActiveContextsubjectIdstring
Returns
IsActiveAsync(IsActiveContext, CancellationToken)
Determines whether the subject is still active and allowed to receive tokens.
public virtual Task IsActiveAsync(IsActiveContext context, CancellationToken cancellationToken = default)
Parameters
contextIsActiveContextcancellationTokenCancellationToken
Returns
Remarks
Inactive when there is no such user; otherwise as IsUserActiveAsync(TUser) says.
Exceptions
- ArgumentNullException
contextis null.- InvalidOperationException
The subject is null or carries no
subclaim.
IsActiveAsync(IsActiveContext, TUser)
Whether this user is active, as IsUserActiveAsync(TUser) says.
protected virtual Task IsActiveAsync(IsActiveContext context, TUser user)
Parameters
contextIsActiveContextuserTUser
Returns
IsUserActiveAsync(TUser)
Whether a user that exists may still get tokens. Yes, unless a host deriving from this class says otherwise.
public virtual Task<bool> IsUserActiveAsync(TUser user)
Parameters
userTUser