Skip to main content

Definition

Assembly: Microsoft.OData.Mcp.Authentication.dll Namespace: Microsoft.OData.Mcp.Authentication.Services

Syntax

Summary

Provides services for validating JWT tokens and extracting user context.

Remarks

This service handles the core token validation logic, including signature verification, claim extraction, and scope validation. It provides a abstraction layer over the underlying JWT validation mechanisms.

Methods

ExtractUserContext Abstract

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.

Exceptions

GetAuthorizationMetadataAsync Abstract

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.

Exceptions

GetTokenLifetime Abstract

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.

Exceptions

HasRequiredScopes Abstract

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.

Exceptions

IsTokenExpired Abstract

Determines if a token is expired based on its claims.

Syntax

Parameters

Returns

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

Exceptions

ValidateTokenAsync Abstract

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.

Exceptions

ValidateTokenAsync Abstract

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.

Exceptions