Skip to main content

Definition

Assembly: Microsoft.OData.Mcp.Authentication.dll Namespace: Microsoft.OData.Mcp.Authentication.Models Inheritance: System.Object

Syntax

Summary

Represents a token that has been delegated for use with a downstream service.

Remarks

This class encapsulates the result of token delegation operations, including the delegated token itself, its metadata, and information about how it was obtained.

Constructors

.ctor

Initializes a new instance of the DelegatedToken class.

Syntax

.ctor

Initializes a new instance of the DelegatedToken class with the specified access token and target service.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from object

Syntax

Properties

AccessToken

Gets or sets the delegated access token.

Syntax

Property Value

Type: string The access token that can be used to authenticate with the target service.

Remarks

This token should be included in the Authorization header when making requests to the target service. The format is typically “Bearer ”.

CanRefresh

Gets or sets a value indicating whether this token can be refreshed.

Syntax

Property Value

Type: bool true if the token can be refreshed; otherwise, false.

Remarks

This is determined by whether a refresh token is available and the delegation strategy supports refresh operations.

DelegationStrategy

Gets or sets the delegation strategy used to obtain this token.

Syntax

Property Value

Type: Microsoft.OData.Mcp.Authentication.Models.TokenForwardingStrategy The strategy that was used for token delegation.

Remarks

This information can be useful for debugging, auditing, and determining what operations are possible with the token (e.g., refresh capabilities).

ExpiresAt

Gets or sets the token expiration time.

Syntax

Property Value

Type: System.Nullable<System.DateTime> The UTC date and time when the token expires.

Remarks

After this time, the token will no longer be valid for authentication. If a refresh token is available, it can be used to obtain a new access token.

IsExpired

Gets a value indicating whether this token is expired.

Syntax

Property Value

Type: bool true if the token is expired; otherwise, false.

IssuedAt

Gets or sets the time when the token was issued.

Syntax

Property Value

Type: System.DateTime The UTC date and time when the token was issued.

Remarks

This timestamp indicates when the token delegation operation completed successfully and the token became available for use.

Metadata

Gets or sets additional metadata about the token delegation.

Syntax

Property Value

Type: System.Collections.Generic.Dictionary<string, object> A dictionary of metadata key-value pairs.

Remarks

This can include information such as the delegation endpoint used, client credentials applied, or other context that might be useful for debugging or auditing.

OriginalToken

Gets or sets the original token that was used for delegation.

Syntax

Property Value

Type: string? The user’s original token that was delegated.

Remarks

This is stored for auditing purposes and potential token refresh operations. It should be handled securely and not logged or exposed unnecessarily.

RefreshToken

Gets or sets the refresh token, if available.

Syntax

Property Value

Type: string? The refresh token that can be used to obtain new access tokens.

Remarks

Refresh tokens allow obtaining new access tokens without requiring user re-authentication. Not all delegation scenarios provide refresh tokens.

RemainingLifetime

Gets the remaining lifetime of the token.

Syntax

Property Value

Type: System.Nullable<System.TimeSpan> The time remaining before the token expires, or null if no expiration is set.

Scopes

Gets or sets the scopes granted for this token.

Syntax

Property Value

Type: System.Collections.Generic.List<string> A collection of OAuth2 scopes that define what the token can access.

Remarks

These scopes may be a subset of the originally requested scopes, depending on what the authorization server granted for the target service.

TargetAudience

Gets or sets the target audience for the token.

Syntax

Property Value

Type: string? The audience claim for which the token was issued.

Remarks

This is the intended recipient of the token and should match the target service’s expected audience value.

TargetServiceId

Gets or sets the target service identifier.

Syntax

Property Value

Type: string The identifier of the service this token is intended for.

Remarks

This identifies which service configuration was used to obtain the token and can be used for routing and caching decisions.

TokenType

Gets or sets the type of the token.

Syntax

Property Value

Type: string The token type (e.g., “Bearer”, “JWT”).

Remarks

This indicates how the token should be used in HTTP requests. Most OAuth2 implementations use “Bearer” tokens.

Methods

AddMetadata

Adds metadata to the delegated token.

Syntax

Parameters

Exceptions

CreateFromExchange

Creates a delegated token from a token exchange result.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.DelegatedToken A delegated token configured for token exchange.

Exceptions

CreateFromOnBehalfOf

Creates a delegated token from an on-behalf-of flow result.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.DelegatedToken A delegated token configured for on-behalf-of flow.

Exceptions

CreatePassThrough

Creates a delegated token for pass-through scenarios.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.DelegatedToken A delegated token configured for pass-through.

Exceptions

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetAuthorizationHeaderValue

Gets the authorization header value for HTTP requests.

Syntax

Returns

Type: string The complete authorization header value (e.g., “Bearer ”).

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetMetadata

Gets metadata value by key.

Syntax

Parameters

Returns

Type: T? The metadata value if found and of the correct type; otherwise, the default value.

Type Parameters

  • T - The type of the metadata value.

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ShouldRefresh

Determines whether the token should be refreshed based on its expiration time.

Syntax

Parameters

Returns

Type: bool true if the token should be refreshed; otherwise, false.

ToString Override

Returns a string representation of the delegated token.

Syntax

Returns

Type: string A summary of the delegated token.

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?

WithUpdatedToken

Creates a copy of the delegated token with updated values.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.DelegatedToken A new delegated token instance with updated values.