<!-- llms.txt: https://workos.com/llms.txt -->

# Session

Represents an authenticated user's connection to your application. A session is created when a user signs in through AuthKit and contains information about the authentication method, device details, and session status.

## List sessions

Get a list of all active sessions for a specific user.

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/user_management/users/user_01EHZNVPK3SFK441A1RGBFSHRT/sessions" \
  --header "Authorization: Bearer sk_example_123456789"
```

```js language="js" title="Request" tab="1"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const sessions = await workos.userManagement.listSessions(
  'user_01E4ZCR3C56J083X43JQXF3JK5',
);
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.user_management.list_sessions(id: "user_01EHZNVPK3SFK441A1RGBFSHRT")
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.user_management.list_sessions(id_="user_01EHZNVPK3SFK441A1RGBFSHRT")
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.UserManagement().ListSessions(context.Background(), "user_01EHZNVPK3SFK441A1RGBFSHRT")
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->userManagement()->listSessions(id: "user_01EHZNVPK3SFK441A1RGBFSHRT");
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.userManagement.listSessions("user_01EHZNVPK3SFK441A1RGBFSHRT");
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.UserManagement.ListSessionsAsync("user_01EHZNVPK3SFK441A1RGBFSHRT");
```

```rust language="rust" title="Request" tab="1"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .user_management()
        .list_sessions("user_01EHZNVPK3SFK441A1RGBFSHRT")
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "object": "list",
  "data": [
    {
      "object": "session",
      "id": "session_01H93ZY4F80QPBEZ1R5B2SHQG8",
      "impersonator": {
        "email": "admin@foocorp.com",
        "reason": "Investigating an issue with the customer's account."
      },
      "ip_address": "198.51.100.42",
      "organization_id": "org_01H945H0YD4F97JN9MATX7BYAG",
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
      "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5",
      "auth_method": "sso",
      "status": "active",
      "expires_at": "2026-01-15T12:00:00.000Z",
      "ended_at": null,
      "created_at": "2026-01-15T12:00:00.000Z",
      "updated_at": "2026-01-15T12:00:00.000Z"
    }
  ],
  "list_metadata": {
    "before": "session_01HXYZ123456789ABCDEFGHIJ",
    "after": "session_01HXYZ987654321KJIHGFEDCBA"
  }
}
```

:::

## Revoke Session

Revoke a [user session](https://workos.com/docs/reference/authkit/session).

:::code-group{title="Request"}

```bash language="curl"
curl --request POST \
  --url https://api.workos.com/user_management/sessions/revoke \
  --header "Authorization: Bearer sk_example_123456789" \
  --header "Content-Type: application/json" \
  -d @- <<BODY
  {
    "session_id": "session_01E4ZCR3C56J083X43JQXF3JK5"
  }
BODY
```

```js language="js"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

await workos.userManagement.revokeSession({
  sessionId: 'session_01E4ZCR3C56J083X43JQXF3JK5',
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.user_management.revoke_session(session_id: "session_01H93ZY4F80QPBEZ1R5B2SHQG8")
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.user_management.revoke_session(session_id="session_01H93ZY4F80QPBEZ1R5B2SHQG8")
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.UserManagement().RevokeSession(context.Background(), &workos.UserManagementRevokeSessionParams{
		SessionID: "session_01H93ZY4F80QPBEZ1R5B2SHQG8",
	})
	if err != nil {
		panic(err)
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->userManagement()
    ->revokeSession(sessionId: "session_01H93ZY4F80QPBEZ1R5B2SHQG8");
```

```java language="java"
import com.workos.WorkOS;
import com.workos.usermanagement.UserManagementApi.RevokeSessionOptions;

WorkOS workos = new WorkOS("sk_example_123456789");

RevokeSessionOptions options = RevokeSessionOptions.builder()
                                   .sessionId("session_01H93ZY4F80QPBEZ1R5B2SHQG8")
                                   .build();

workos.userManagement.revokeSession(options);
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.UserManagement.RevokeSessionAsync(new UserManagementRevokeSessionOptions {
    SessionId = "session_01H93ZY4F80QPBEZ1R5B2SHQG8",
});
```

```rust language="rust"
use workos::Client;
use workos::user_management::RevokeSessionParams;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .user_management()
        .revoke_session(
            RevokeSessionParams {
                session_id: "session_01H93ZY4F80QPBEZ1R5B2SHQG8".into(),
                ..Default::default()
            }
        )
        .await?;

    Ok(())
}
```

:::

### session

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | "session" | Yes | Distinguishes the session object. |
| `id` | string | Yes | The unique ID of the session. |
| `user_id` | string | Yes | The ID of the user this session belongs to. |
| `organization_id` | string | No | The ID of the organization this session is associated with. |
| `status` | string | Yes | The current status of the session. |
| `auth_method` | string | Yes | The authentication method used to create this session. |
| `ip_address` | string | No | The IP address from which the session was created. |
| `user_agent` | string | No | The user agent string from the device that created the session. |
| `impersonator` | object | No | Information about the impersonator if this session was created via impersonation. |
| `expires_at` | string | Yes | The timestamp when the session expires. |
| `ended_at` | string | No | The timestamp when the session ended. |
| `created_at` | string | Yes | The timestamp when the session was created. |
| `updated_at` | string | Yes | The timestamp when the session was last updated. |

### GET /user_management/users/{id}/sessions

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The ID of the user. |
| `before` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`. |
| `after` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`. |
| `limit` | integer | No | Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`. |
| `order` | "normal" \| "desc" \| "asc" | No | Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to `desc`. |

### POST /user_management/sessions/revoke

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `session_id` | string | Yes | The ID of the session to revoke. This can be extracted from the `sid` claim of the access token. |