Table of Contents

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

userManager UserManager<TUser>

Finds the user by subject id.

claimsFactory IUserClaimsPrincipalFactory<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

userManager UserManager<TUser>

Finds the user by subject id.

claimsFactory IUserClaimsPrincipalFactory<TUser>

Makes the user's claims.

logger ILogger<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

subjectId string

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

context ProfileDataRequestContext
subjectId string

Returns

Task

GetProfileDataAsync(ProfileDataRequestContext, CancellationToken)

Adds the requested claims to IssuedClaims.

public virtual Task GetProfileDataAsync(ProfileDataRequestContext context, CancellationToken cancellationToken = default)

Parameters

context ProfileDataRequestContext
cancellationToken CancellationToken

Returns

Task

Remarks

Issues the requested ones of the claims ClaimsFactory makes for the user; nothing when there is no such user.

Exceptions

ArgumentNullException

context is null.

InvalidOperationException

The subject is null or carries no sub claim, 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

context ProfileDataRequestContext
user TUser

Returns

Task

GetUserClaimsAsync(TUser)

The user's claims, as ClaimsFactory makes them.

protected virtual Task<ClaimsPrincipal> GetUserClaimsAsync(TUser user)

Parameters

user TUser

Returns

Task<ClaimsPrincipal>

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

context IsActiveContext
subjectId string

Returns

Task

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

context IsActiveContext
cancellationToken CancellationToken

Returns

Task

Remarks

Inactive when there is no such user; otherwise as IsUserActiveAsync(TUser) says.

Exceptions

ArgumentNullException

context is null.

InvalidOperationException

The subject is null or carries no sub claim.

IsActiveAsync(IsActiveContext, TUser)

Whether this user is active, as IsUserActiveAsync(TUser) says.

protected virtual Task IsActiveAsync(IsActiveContext context, TUser user)

Parameters

context IsActiveContext
user TUser

Returns

Task

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

user TUser

Returns

Task<bool>