Definition
Assembly: Microsoft.OData.Mcp.Authentication.dll Namespace: Microsoft.OData.Mcp.Authentication.Models Inheritance: System.ObjectSyntax
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
| Name | Type | Description |
|---|---|---|
principal | System.Security.Claims.ClaimsPrincipal | The validated claims principal. |
Exceptions
| Exception | Description |
|---|---|
ArgumentNullException | Thrown when principal is null. |
.ctor
Initializes a new instance of the TokenValidationResult class for a failed validation.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
error | string | The validation error. |
errorDescription | string? | The detailed error description. |
exception | System.Exception? | The exception that caused the failure. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when error is null or whitespace. |
.ctor Inherited
Inherited from
objectSyntax
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
| Name | Type | Description |
|---|---|---|
key | string | The metadata key. |
value | object | The metadata value. |
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when key 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
Failure
Creates a failed validation result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
error | string | The validation error. |
errorDescription | string? | The detailed error description. |
exception | System.Exception? | The exception that caused the failure. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.TokenValidationResult
A failed token validation result.
Exceptions
| Exception | Description |
|---|---|
ArgumentException | Thrown when error is null or whitespace. |
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.
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
objectSyntax
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
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
Success
Creates a successful validation result.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
principal | System.Security.Claims.ClaimsPrincipal | The validated claims principal. |
Returns
Type:Microsoft.OData.Mcp.Authentication.Models.TokenValidationResult
A successful token validation result.
Exceptions
| Exception | Description |
|---|---|
ArgumentNullException | Thrown when principal is null. |
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
objectSyntax
Returns
Type:string?