Definition
Assembly: Microsoft.OData.Mcp.Authentication.dll Namespace: Microsoft.OData.Mcp.Authentication.Models Inheritance: System.ObjectSyntax
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
| Name | Type | Description |
|---|---|---|
accessToken | string | The delegated access token. |
targetServiceId | string | The target service identifier. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when accessToken or targetServiceId is null or whitespace. |
.ctor Inherited
Inherited from
objectSyntax
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
| Name | Type | Description |
|---|---|---|
key | string | The metadata key. |
value | object | The metadata value. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when key is null or whitespace. |
CreateFromExchange
Creates a delegated token from a token exchange result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
exchangedToken | string | The token received from the exchange. |
targetServiceId | string | The target service identifier. |
originalToken | string? | The original token that was exchanged. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.DelegatedToken
A delegated token configured for token exchange.
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when exchangedToken or targetServiceId is null or whitespace. |
CreateFromOnBehalfOf
Creates a delegated token from an on-behalf-of flow result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
onBehalfOfToken | string | The token received from the on-behalf-of flow. |
targetServiceId | string | The target service identifier. |
originalToken | string? | The original token used for the on-behalf-of flow. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.DelegatedToken
A delegated token configured for on-behalf-of flow.
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when onBehalfOfToken or targetServiceId is null or whitespace. |
CreatePassThrough
Creates a delegated token for pass-through scenarios.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
originalToken | string | The original token to pass through. |
targetServiceId | string | The target service identifier. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.DelegatedToken
A delegated token configured for pass-through.
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when originalToken or targetServiceId is null or whitespace. |
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
obj | object? | - |
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
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
objectSyntax
Returns
Type:int
GetMetadata
Gets metadata value by key.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The metadata key. |
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
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
ShouldRefresh
Determines whether the token should be refreshed based on its expiration time.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
refreshThreshold | System.TimeSpan | The time before expiration when refresh should be considered. |
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
objectSyntax
Returns
Type:string?
WithUpdatedToken
Creates a copy of the delegated token with updated values.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
newAccessToken | string | The new access token value. |
newExpiresAt | System.Nullable<System.DateTime> | The new expiration time. |
newRefreshToken | string? | The new refresh token. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.DelegatedToken
A new delegated token instance with updated values.