> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# UserContext

> Represents the user context extracted from an authenticated request.

export function DocsBadge({text, variant = 'neutral'}) {
  const variantClasses = {
    success: 'mint-bg-green-500/10 mint-text-green-600 dark:mint-text-green-400 mint-border-green-500/20',
    neutral: 'mint-bg-slate-500/10 mint-text-slate-600 dark:mint-text-slate-400 mint-border-slate-500/20',
    info: 'mint-bg-blue-500/10 mint-text-blue-600 dark:mint-text-blue-400 mint-border-blue-500/20',
    warning: 'mint-bg-amber-500/10 mint-text-amber-600 dark:mint-text-amber-400 mint-border-amber-500/20',
    danger: 'mint-bg-red-500/10 mint-text-red-600 dark:mint-text-red-400 mint-border-red-500/20'
  };
  const classes = variantClasses[variant] || variantClasses.neutral;
  return <span className={`mint-inline-flex mint-items-center mint-px-2 mint-py-0.5 mint-rounded-full mint-text-xs mint-font-medium mint-tracking-wide mint-border mint-ml-1.5 mint-align-middle mint-whitespace-nowrap ${classes}`}>
      {text}
    </span>;
}

## Definition

**Assembly:** Microsoft.OData.Mcp.Authentication.dll

**Namespace:** Microsoft.OData.Mcp.Authentication.Models

**Inheritance:** System.Object

## Syntax

```csharp theme={"dark"}
Microsoft.OData.Mcp.Authentication.Models.UserContext
```

## Summary

Represents the user context extracted from an authenticated request.

## Remarks

This class encapsulates the user's identity, authorization information, and
other context data needed for processing MCP requests on behalf of the user.

## Constructors

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  .ctor

Initializes a new instance of the [UserContext](/odata-mcp/api-reference/Microsoft/OData/Mcp/Authentication/Models/UserContext) class.

#### Syntax

```csharp theme={"dark"}
public UserContext()
```

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  .ctor

Initializes a new instance of the [UserContext](/odata-mcp/api-reference/Microsoft/OData/Mcp/Authentication/Models/UserContext) class with the specified user ID.

#### Syntax

```csharp theme={"dark"}
public UserContext(string userId)
```

#### Parameters

| Name     | Type     | Description                   |
| -------- | -------- | ----------------------------- |
| `userId` | `string` | The user's unique identifier. |

#### Exceptions

| Exception           | Description                                 |
| ------------------- | ------------------------------------------- |
| `ArgumentException` | Thrown when *userId* is null or whitespace. |

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  .ctor <DocsBadge text="Inherited" variant="neutral" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AdditionalClaims

Gets or sets additional user claims.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.Dictionary<string, string> AdditionalClaims { get; set; }
```

#### Property Value

Type: `System.Collections.Generic.Dictionary<string, string>`
A dictionary of additional claims extracted from the token.

#### Remarks

This contains any custom claims that are not covered by the standard
properties but may be needed for authorization or business logic.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Audience

Gets or sets the audience for which the token was issued.

#### Syntax

```csharp theme={"dark"}
public string Audience { get; set; }
```

#### Property Value

Type: `string?`
The audience identifier from the JWT token.

#### Remarks

This identifies the intended recipient of the token, which should
match the MCP server's configuration.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AuthenticatedAt

Gets or sets the time when the user was authenticated.

#### Syntax

```csharp theme={"dark"}
public System.DateTime AuthenticatedAt { get; set; }
```

#### Property Value

Type: `System.DateTime?`
The UTC date and time when authentication occurred.

#### Remarks

This timestamp is used for session management, auditing, and
security analysis.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  AuthenticationMethod

Gets or sets the authentication method used.

#### Syntax

```csharp theme={"dark"}
public string AuthenticationMethod { get; set; }
```

#### Property Value

Type: `string?`
The method used to authenticate the user (e.g., "Bearer", "JWT").

#### Remarks

This indicates how the user was authenticated, which can be useful
for security auditing and compliance reporting.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  ClientId

Gets or sets the client application identifier.

#### Syntax

```csharp theme={"dark"}
public string ClientId { get; set; }
```

#### Property Value

Type: `string?`
The identifier of the client application that initiated the request.

#### Remarks

This identifies which application the user is accessing the MCP server
through, which can be useful for auditing and access control.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  DisplayName

Gets or sets the user's display name.

#### Syntax

```csharp theme={"dark"}
public string DisplayName { get; set; }
```

#### Property Value

Type: `string?`
The display name or username of the authenticated user.

#### Remarks

This is typically extracted from claims like 'name', 'preferred\_username',
or 'upn' and is used for display purposes in logs and audit trails.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Email

Gets or sets the user's email address.

#### Syntax

```csharp theme={"dark"}
public string Email { get; set; }
```

#### Property Value

Type: `string?`
The email address of the authenticated user.

#### Remarks

This is typically extracted from the 'email' claim and can be used
for notifications or audit purposes.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Issuer

Gets or sets the issuer of the authentication token.

#### Syntax

```csharp theme={"dark"}
public string Issuer { get; set; }
```

#### Property Value

Type: `string?`
The issuer identifier from the JWT token.

#### Remarks

This identifies which authorization server issued the token, which is
important for multi-provider scenarios and security auditing.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Roles

Gets or sets the user's roles.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.List<string> Roles { get; set; }
```

#### Property Value

Type: `System.Collections.Generic.List<string>`
A collection of roles assigned to the user.

#### Remarks

Roles provide a higher-level grouping of permissions and are typically
extracted from 'roles' or similar claims in the token.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Scopes

Gets or sets the OAuth2 scopes granted to the user.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.List<string> Scopes { get; set; }
```

#### Property Value

Type: `System.Collections.Generic.List<string>`
A collection of OAuth2 scopes that define the user's permissions.

#### Remarks

These scopes are extracted from the token and determine what operations
the user is authorized to perform through the MCP server.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  TenantId

Gets or sets the tenant identifier for multi-tenant scenarios.

#### Syntax

```csharp theme={"dark"}
public string TenantId { get; set; }
```

#### Property Value

Type: `string?`
The identifier of the tenant the user belongs to.

#### Remarks

This is used in multi-tenant deployments to isolate data and operations
between different organizational units or customers.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Token

Gets or sets the original JWT token.

#### Syntax

```csharp theme={"dark"}
public string Token { get; set; }
```

#### Property Value

Type: `string?`
The raw JWT token that was used for authentication.

#### Remarks

This token can be forwarded to downstream services for delegation
scenarios while maintaining the user's identity.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  TokenExpiresAt

Gets or sets the token expiration time.

#### Syntax

```csharp theme={"dark"}
public System.Nullable<System.DateTime> TokenExpiresAt { get; set; }
```

#### Property Value

Type: `System.Nullable<System.DateTime?>?`
The UTC date and time when the token expires.

#### Remarks

This is used to determine when the user's session will expire and
when token refresh might be needed.

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  UserId

Gets or sets the user's unique identifier.

#### Syntax

```csharp theme={"dark"}
public required string UserId { get; set; }
```

#### Property Value

Type: `string`
The unique identifier for the authenticated user.

#### Remarks

This is typically extracted from the 'sub' (subject) claim in the JWT token
and uniquely identifies the user across the system.

## Methods

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Equals <DocsBadge text="Inherited" variant="neutral" /> <DocsBadge text="Virtual" variant="warning" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name  | Type      | Description |
| ----- | --------- | ----------- |
| `obj` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  Equals <DocsBadge text="Inherited" variant="neutral" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name   | Type      | Description |
| ------ | --------- | ----------- |
| `objA` | `object?` | -           |
| `objB` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  FromClaimsPrincipal

Creates a user context from a claims principal.

#### Syntax

```csharp theme={"dark"}
public static Microsoft.OData.Mcp.Authentication.Models.UserContext FromClaimsPrincipal(System.Security.Claims.ClaimsPrincipal principal, string token = null)
```

#### Parameters

| Name        | Type                                     | Description                                        |
| ----------- | ---------------------------------------- | -------------------------------------------------- |
| `principal` | `System.Security.Claims.ClaimsPrincipal` | The claims principal to extract user context from. |
| `token`     | `string?`                                | The original JWT token (optional).                 |

#### Returns

Type: `Microsoft.OData.Mcp.Authentication.Models.UserContext`
A user context populated with information from the claims principal.

#### Exceptions

| Exception                   | Description                                                 |
| --------------------------- | ----------------------------------------------------------- |
| `ArgumentNullException`     | Thrown when *principal* is null.                            |
| `InvalidOperationException` | Thrown when the principal does not contain a subject claim. |

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  GetAdditionalClaim

Gets an additional claim value by type.

#### Syntax

```csharp theme={"dark"}
public string GetAdditionalClaim(string claimType)
```

#### Parameters

| Name        | Type     | Description                 |
| ----------- | -------- | --------------------------- |
| `claimType` | `string` | The claim type to retrieve. |

#### Returns

Type: `string?`
The claim value if found; otherwise, null.

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  GetHashCode <DocsBadge text="Inherited" variant="neutral" /> <DocsBadge text="Virtual" variant="warning" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  GetRemainingTokenLifetime

Gets the remaining time before the token expires.

#### Syntax

```csharp theme={"dark"}
public System.Nullable<System.TimeSpan> GetRemainingTokenLifetime()
```

#### Returns

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

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  GetType <DocsBadge text="Inherited" variant="neutral" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  HasAllScopes

Determines whether the user has all of the specified scopes.

#### Syntax

```csharp theme={"dark"}
public bool HasAllScopes(System.Collections.Generic.IEnumerable<string> requiredScopes)
```

#### Parameters

| Name             | Type                                             | Description              |
| ---------------- | ------------------------------------------------ | ------------------------ |
| `requiredScopes` | `System.Collections.Generic.IEnumerable<string>` | The scopes to check for. |

#### Returns

Type: `bool`
`true` if the user has all of the required scopes; otherwise, `false`.

#### Exceptions

| Exception               | Description                           |
| ----------------------- | ------------------------------------- |
| `ArgumentNullException` | Thrown when *requiredScopes* is null. |

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  HasAnyRole

Determines whether the user has any of the specified roles.

#### Syntax

```csharp theme={"dark"}
public bool HasAnyRole(System.Collections.Generic.IEnumerable<string> requiredRoles)
```

#### Parameters

| Name            | Type                                             | Description             |
| --------------- | ------------------------------------------------ | ----------------------- |
| `requiredRoles` | `System.Collections.Generic.IEnumerable<string>` | The roles to check for. |

#### Returns

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

#### Exceptions

| Exception               | Description                          |
| ----------------------- | ------------------------------------ |
| `ArgumentNullException` | Thrown when *requiredRoles* is null. |

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  HasAnyScope

Determines whether the user has any of the specified scopes.

#### Syntax

```csharp theme={"dark"}
public bool HasAnyScope(System.Collections.Generic.IEnumerable<string> requiredScopes)
```

#### Parameters

| Name             | Type                                             | Description              |
| ---------------- | ------------------------------------------------ | ------------------------ |
| `requiredScopes` | `System.Collections.Generic.IEnumerable<string>` | The scopes to check for. |

#### Returns

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

#### Exceptions

| Exception               | Description                           |
| ----------------------- | ------------------------------------- |
| `ArgumentNullException` | Thrown when *requiredScopes* is null. |

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  IsTokenExpired

Determines whether the user's token is expired.

#### Syntax

```csharp theme={"dark"}
public bool IsTokenExpired()
```

#### Returns

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

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  MemberwiseClone <DocsBadge text="Inherited" variant="neutral" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  ReferenceEquals <DocsBadge text="Inherited" variant="neutral" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name   | Type      | Description |
| ------ | --------- | ----------- |
| `objA` | `object?` | -           |
| `objB` | `object?` | -           |

#### Returns

Type: `bool`

### <Icon icon="code-merge" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  ToString <DocsBadge text="Override" variant="info" />

Returns a string representation of the user context.

#### Syntax

```csharp theme={"dark"}
public override string ToString()
```

#### Returns

Type: `string`
A summary of the user context.

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} style={{ paddingRight: '8px' }} />  ToString <DocsBadge text="Inherited" variant="neutral" /> <DocsBadge text="Virtual" variant="warning" />

<Note>Inherited from `object`</Note>

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`
