Skip to main content

Definition

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

Syntax

Summary

Represents the result of a token validation operation.

Remarks

This class encapsulates the outcome of token validation, including success/failure status, the validated principal, and any validation errors that occurred during the process.

Constructors

.ctor

Initializes a new instance of the TokenValidationResult class.

Syntax

.ctor

Initializes a new instance of the TokenValidationResult class for a successful validation.

Syntax

Parameters

Exceptions

.ctor

Initializes a new instance of the TokenValidationResult class for a failed validation.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from object

Syntax

Properties

Error

Gets or sets the validation error that occurred during token validation.

Syntax

Property Value

Type: string? The validation error if validation failed; otherwise, null.

Remarks

This provides detailed information about why token validation failed, which can be useful for debugging and security auditing.

ErrorDescription

Gets or sets the detailed error description.

Syntax

Property Value

Type: string? A detailed description of the validation error; otherwise, null.

Remarks

This provides additional context about the validation failure, such as specific claims that were invalid or missing.

Exception

Gets or sets the exception that caused the validation failure.

Syntax

Property Value

Type: System.Exception? The exception that occurred during validation; otherwise, null.

Remarks

This is typically used for logging and debugging purposes to understand the root cause of validation failures.

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; otherwise, null.

Remarks

This is extracted from the token’s ‘exp’ claim and represents when the token will no longer be valid for authentication.

IssuedAt

Gets or sets the token issued time.

Syntax

Property Value

Type: System.Nullable<System.DateTime?>? The UTC date and time when the token was issued; otherwise, null.

Remarks

This is extracted from the token’s ‘iat’ claim and represents when the token was originally created by the authorization server.

IsValid

Gets or sets a value indicating whether the token validation was successful.

Syntax

Property Value

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

Metadata

Gets or sets additional validation metadata.

Syntax

Property Value

Type: System.Collections.Generic.Dictionary<string, object> A dictionary of additional information about the validation process.

Remarks

This can include information such as the validation time, token issuer, audience, or other metadata that might be useful for auditing or debugging.

NotBefore

Gets or sets the token not-before time.

Syntax

Property Value

Type: System.Nullable<System.DateTime?>? The UTC date and time before which the token is not valid; otherwise, null.

Remarks

This is extracted from the token’s ‘nbf’ claim and represents the earliest time the token can be used for authentication.

Principal

Gets or sets the claims principal from the validated token.

Syntax

Property Value

Type: System.Security.Claims.ClaimsPrincipal? The claims principal if validation was successful; otherwise, null.

Remarks

This principal contains all the claims extracted from the JWT token and can be used for authorization decisions and user context extraction.

Methods

AddMetadata

Adds metadata to the validation result.

Syntax

Parameters

Exceptions

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

Failure

Creates a failed validation result.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.TokenValidationResult A failed token validation result.

Exceptions

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.

GetRemainingLifetime

Gets the remaining lifetime of the token.

Syntax

Returns

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

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

IsExpired

Determines whether the token is currently expired.

Syntax

Returns

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

IsNotYetValid

Determines whether the token is not yet valid.

Syntax

Returns

Type: bool true if the token is not yet valid; otherwise, false.

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

Success

Creates a successful validation result.

Syntax

Parameters

Returns

Type: Microsoft.OData.Mcp.Authentication.Models.TokenValidationResult A successful token validation result.

Exceptions

ToString Override

Returns a string representation of the token validation result.

Syntax

Returns

Type: string A summary of the validation result.

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?