Skip to main content

Definition

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

Syntax

Summary

Provides services for validating JWT tokens and extracting user context.

Remarks

This service handles JWT token validation using Microsoft’s IdentityModel libraries, including automatic discovery of validation keys and comprehensive claim extraction.

Constructors

.ctor

Initializes a new instance of the TokenValidationService class.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from object

Syntax

Methods

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ExtractUserContext

Extracts the user context from a validated claims principal.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.UserContext The user context containing identity and authorization information.

GetAuthorizationMetadataAsync

Gets the authorization metadata from the JWT token for downstream services.

Syntax

Parameters

Returns

Type: System.Threading.Tasks.Task<Microsoft.OData.Mcp.Authentication.Models.AuthorizationMetadata> A task that represents the asynchronous operation. The task result contains the authorization metadata.

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetTokenLifetime

Gets the remaining lifetime of a token.

Syntax

Parameters

Returns

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

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

HasRequiredScopes

Checks if a user has the required scopes for a specific operation.

Syntax

Parameters

Returns

Type: bool true if the user has at least one of the required scopes; otherwise, false.

IsTokenExpired

Determines if a token is expired based on its claims.

Syntax

Parameters

Returns

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

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?

ValidateTokenAsync

Validates a JWT token and returns the principal if valid.

Syntax

Parameters

Returns

Type: System.Threading.Tasks.Task<System.Security.Claims.ClaimsPrincipal?> A task that represents the asynchronous validation operation. The task result contains the claims principal if the token is valid, or null if invalid.

ValidateTokenAsync

Validates a JWT token with additional validation parameters.

Syntax

Parameters

Returns

Type: System.Threading.Tasks.Task<Microsoft.OData.Mcp.Authentication.Models.TokenValidationResult> A task that represents the asynchronous validation operation. The task result contains the validation result.
  • Microsoft.OData.Mcp.Authentication.Services.ITokenValidationService