Skip to main content

Definition

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

Syntax

Microsoft.OData.Mcp.Authentication.Models.TokenDelegationOptions

Summary

Configuration options for token delegation to downstream services.

Remarks

These options control how authentication tokens are forwarded from the MCP server to downstream OData services and other dependencies. Token delegation preserves the user’s identity throughout the request chain.

Constructors

.ctor

Initializes a new instance of the TokenDelegationOptions class.

Syntax

public TokenDelegationOptions()

.ctor Inherited

Inherited from object

Syntax

public Object()

Properties

CacheDuration

Gets or sets the cache duration for delegated tokens.

Syntax

public System.TimeSpan CacheDuration { get; set; }

Property Value

Type: System.TimeSpan The duration to cache delegated tokens.

Remarks

This duration should be shorter than the token’s actual lifetime to ensure cached tokens don’t expire unexpectedly. The cache automatically handles token refresh when possible.

CacheTokens

Gets or sets a value indicating whether to cache delegated tokens.

Syntax

public bool CacheTokens { get; set; }

Property Value

Type: bool true if delegated tokens should be cached; otherwise, false.

Remarks

Caching delegated tokens can improve performance by avoiding repeated token exchange operations. Cached tokens are automatically refreshed before expiration.

Enabled

Gets or sets a value indicating whether token delegation is enabled.

Syntax

public bool Enabled { get; set; }

Property Value

Type: bool true if token delegation is enabled; otherwise, false.

Remarks

When enabled, the MCP server will forward authentication tokens to downstream services. When disabled, the server may use alternative authentication methods for downstream calls, such as service-to-service authentication.

RetryPolicy

Gets or sets the retry policy for failed token delegation operations.

Syntax

public Microsoft.OData.Mcp.Authentication.Models.RetryPolicyOptions RetryPolicy { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Authentication.Models.RetryPolicyOptions Configuration for retrying failed token operations.

Remarks

Retry policies help handle transient failures in token delegation, such as network issues or temporary service unavailability. They should be configured carefully to avoid overwhelming downstream services.

Strategy

Gets or sets the token forwarding strategy.

Syntax

public Microsoft.OData.Mcp.Authentication.Models.TokenForwardingStrategy Strategy { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Authentication.Models.TokenForwardingStrategy The strategy for forwarding tokens to downstream services.

Remarks

Different strategies provide different levels of security and functionality:
  • PassThrough: Forward the original token as-is
  • Exchange: Exchange the token for a new one scoped to the downstream service
  • OnBehalfOf: Use OAuth2 on-behalf-of flow for token delegation

TargetServices

Gets or sets the target services for token delegation.

Syntax

public System.Collections.Generic.List<Microsoft.OData.Mcp.Authentication.Models.TargetServiceOptions> TargetServices { get; set; }

Property Value

Type: System.Collections.Generic.List<Microsoft.OData.Mcp.Authentication.Models.TargetServiceOptions> A collection of service configurations for token forwarding.

Remarks

Each target service can have its own delegation configuration, including different forwarding strategies, scopes, and authentication parameters.

Timeout

Gets or sets the timeout for token delegation operations.

Syntax

public System.TimeSpan Timeout { get; set; }

Property Value

Type: System.TimeSpan The timeout duration for token delegation operations.

Remarks

This timeout applies to operations like token exchange, on-behalf-of flows, and communication with token endpoints. Operations that exceed this timeout will be cancelled.

TokenExchange

Gets or sets the token exchange options for services that support token exchange.

Syntax

public Microsoft.OData.Mcp.Authentication.Models.TokenExchangeOptions TokenExchange { get; set; }

Property Value

Type: Microsoft.OData.Mcp.Authentication.Models.TokenExchangeOptions Configuration for OAuth2 token exchange flows.

Remarks

Token exchange allows the MCP server to obtain tokens with different scopes or audiences for downstream services while maintaining the user’s identity.

ValidateBeforeForwarding

Gets or sets a value indicating whether to validate delegated tokens before forwarding.

Syntax

public bool ValidateBeforeForwarding { get; set; }

Property Value

Type: bool true if delegated tokens should be validated; otherwise, false.

Remarks

Validating delegated tokens ensures they are properly formatted and not expired before forwarding them to downstream services. This can prevent downstream authentication failures but adds processing overhead.

Methods

AddOrUpdateTargetService

Adds or updates target service options.

Syntax

public void AddOrUpdateTargetService(Microsoft.OData.Mcp.Authentication.Models.TargetServiceOptions targetService)

Parameters

NameTypeDescription
targetServiceMicrosoft.OData.Mcp.Authentication.Models.TargetServiceOptionsThe target service options to add or update.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when targetService is null.

Equals Inherited Virtual

Inherited from object

Syntax

public virtual bool Equals(object obj)

Parameters

NameTypeDescription
objobject?-

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

public static bool Equals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetTargetService

Gets the target service options for a specific service identifier.

Syntax

public Microsoft.OData.Mcp.Authentication.Models.TargetServiceOptions GetTargetService(string serviceId)

Parameters

NameTypeDescription
serviceIdstringThe identifier of the target service.

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.TargetServiceOptions? The target service options, or null if not found.

GetType Inherited

Inherited from object

Syntax

public System.Type GetType()

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

protected internal object MemberwiseClone()

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

public static bool ReferenceEquals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

ToString Override

Returns a string representation of the token delegation options.

Syntax

public override string ToString()

Returns

Type: string A summary of the token delegation configuration.

ToString Inherited Virtual

Inherited from object

Syntax

public virtual string ToString()

Returns

Type: string?

Validate

Validates the token delegation options for consistency and completeness.

Syntax

public System.Collections.Generic.IEnumerable<string> Validate()

Returns

Type: System.Collections.Generic.IEnumerable<string> A collection of validation errors, or an empty collection if the options are valid.