Class AccessToken
Simple implementation of IAccessToken used for message context population.
public sealed class AccessToken : IAccessToken, IAuthenticationToken, IAuthorizationPolicy, IPolicy
- Inheritance
-
AccessToken
- Implements
- Inherited Members
Constructors
AccessToken(IAuthenticationToken, IAuthorizationPolicy)
Initializes a new instance of the AccessToken class with the specified authentication and authorization policies.
public AccessToken(IAuthenticationToken authenticationToken, IAuthorizationPolicy authorizationPolicy)
Parameters
authenticationTokenIAuthenticationTokenThe authentication token for the user.
authorizationPolicyIAuthorizationPolicyThe authorization policy for the user.
Exceptions
- InvalidOperationException
Thrown if the user identifiers in the authentication token and authorization policy do not match.
Properties
AuthenticationState
Gets the current authentication state of the token. Indicates whether the user is anonymous, authenticated, or fully identified.
public AuthenticationState AuthenticationState { get; }
Property Value
- AuthenticationState
The current authentication state of the token.
Claims
Gets the claims for this authentication token.
public IEnumerable<Claim>? Claims { get; }
Property Value
- IEnumerable<Claim>
The collection of claims, or null if no claims are available.
FirstName
Gets the first name of the authenticated user. Returns null if the user's identity is not available or not set.
public string? FirstName { get; }
Property Value
FullName
Gets the full name of the authenticated user, constructed from FirstName and LastName. Returns an empty string if neither property is set.
public string FullName { get; }
Property Value
- string
The full name of the authenticated user, or an empty string if neither property is set.
Jwt
Gets or sets the raw JWT (JSON Web Token) string associated with the authentication token. This property can be null if the token has not been issued or is not applicable.
public string? Jwt { get; set; }
Property Value
LastName
Gets the last name of the authenticated user. Returns null if the user's identity is not available or not set.
public string? LastName { get; }
Property Value
Login
Gets the login identifier (e.g., email address or username) of the authenticated user. Returns null if the user's login information is not available.
public string? Login { get; }
Property Value
TenantId
Gets the tenant identifier associated with the authorization policy.
public string TenantId { get; }
Property Value
- string
The tenant identifier.
Methods
FromValues(string?, string)
Creates a AccessToken from the provided user and tenant identifiers.
public static AccessToken FromValues(string? userId, string tenantId)
Parameters
Returns
- AccessToken
A AccessToken instance.
HasGrant(string)
Determines if the user has a grant for the specified activity.
public bool HasGrant(string activityName)
Parameters
activityNamestringThe name of the activity to check for a grant.
Returns
- bool
trueif the user has a grant; otherwise,false.
HasGrant(string, string)
Determines if the user has a grant for a specific resource type and resource ID.
public bool HasGrant(string resourceType, string resourceId)
Parameters
Returns
- bool
trueif the user has a grant; otherwise,false.
HasGrant<TActivity>()
Determines if the user has a grant for a specific activity type.
public bool HasGrant<TActivity>()
Returns
- bool
trueif the user has a grant; otherwise,false.
Type Parameters
TActivityThe activity type to check for a grant.
HasGrant<TResourceType>(string)
Determines if the user has a grant for a specific resource type and resource ID.
public bool HasGrant<TResourceType>(string resourceId)
Parameters
resourceIdstringThe identifier of the resource.
Returns
- bool
trueif the user has a grant; otherwise,false.
Type Parameters
TResourceTypeThe resource type to check.
IsAnonymous()
Determines whether the provided authentication token represents an anonymous user.
public bool IsAnonymous()
Returns
- bool
trueif the token represents an anonymous user; otherwise,false.
IsAuthenticated()
Determines whether the provided authentication token represents an authenticated user.
public bool IsAuthenticated()
Returns
- bool
trueif the token represents an authenticated user; otherwise,false.
IsAuthorized(string, string?)
Determines if the user is authorized to perform an activity on an optional resource.
public bool IsAuthorized(string activityName, string? resourceId)
Parameters
activityNamestringThe name of the activity to authorize.
resourceIdstringThe identifier of the resource, or null if not applicable.
Returns
- bool
trueif the user is authorized; otherwise,false.