Table of Contents

Class AccessToken

Namespace
Excalibur.A3
Assembly
Excalibur.A3.dll

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

authenticationToken IAuthenticationToken

The authentication token for the user.

authorizationPolicy IAuthorizationPolicy

The 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

string

The first name of the user, or null if not available.

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

string

The raw JWT string, or null if not applicable.

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

string

The last name of the user, or null if not available.

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

string

The login identifier, or null if not available.

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

userId string

The user identifier.

tenantId string

The tenant identifier.

Returns

AccessToken

A AccessToken instance.

HasGrant(string)

Determines if the user has a grant for the specified activity.

public bool HasGrant(string activityName)

Parameters

activityName string

The name of the activity to check for a grant.

Returns

bool

true if 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

resourceType string

The type of the resource.

resourceId string

The identifier of the resource.

Returns

bool

true if 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

true if the user has a grant; otherwise, false .

Type Parameters

TActivity

The 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

resourceId string

The identifier of the resource.

Returns

bool

true if the user has a grant; otherwise, false .

Type Parameters

TResourceType

The resource type to check.

IsAnonymous()

Determines whether the provided authentication token represents an anonymous user.

public bool IsAnonymous()

Returns

bool

true if the token represents an anonymous user; otherwise, false .

IsAuthenticated()

Determines whether the provided authentication token represents an authenticated user.

public bool IsAuthenticated()

Returns

bool

true if 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

activityName string

The name of the activity to authorize.

resourceId string

The identifier of the resource, or null if not applicable.

Returns

bool

true if the user is authorized; otherwise, false .