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

# Logout

End a user's session. The user's browser should be redirected to this URL.

# Get logout URL from session cookie

Generates the logout URL by extracting the session ID from the session cookie. Use this over `getLogoutUrl` if you don't have a saved reference to the session ID and you'd like the SDK to handle extracting the session ID from the cookie for you.

:::code-group

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

const workos = new WorkOS('sk_test_123');

const logoutUrl = workos.userManagement.getLogoutUrlFromSessionCookie({
  sessionData: 'sealed_session_cookie_data',
  cookiePassword: 'password_previously_used_to_seal_session_cookie',
});
```

```txt language="url" title="Response" tab="2"
https://api.workos.com/user_management/sessions/logout?
session_id=session_01HQAG1HENBZMAZD82YRXDFC0B
```

:::

# Get logout URL

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/user_management/sessions/logout" \
  -G \
  -d session_id=session_01HQAG1HENBZMAZD82YRXDFC0B \
  -d return_to=https://your-app.com/signed-out
```

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

const workos = new WorkOS('sk_test_123');

const logoutUrl = workos.userManagement.getLogoutUrl({
  sessionId: 'session_01HQAG1HENBZMAZD82YRXDFC0B',
  returnTo: 'https://your-app.com/signed-out',
});
```

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

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

logout_url = WorkOS::UserManagement.get_logout_url(
  session_id: "session_01HQAG1HENBZMAZD82YRXDFC0B",
  return_to: "https://your-app.com/signed-out"
)
```

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

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

logout_url = workos_client.user_management.get_logout_url(
    session_id="session_01HQAG1HENBZMAZD82YRXDFC0B",
    return_to="https://your-app.com/signed-out",
)
```

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

import (
	"context"

	"github.com/workos/workos-go/v2/pkg/usermanagement"
)

func main() {
	usermanagement.SetAPIKey(
		"sk_example_123456789",
	)

	response, err := usermanagement.GetLogoutURL(
		context.Background(),
		usermanagement.GetLogoutURLOpts{
			SessionID: "session_01HQAG1HENBZMAZD82YRXDFC0B",
			ReturnTo:  "https://your-app.com/signed-out",
		},
	)
}
```

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

WorkOS\WorkOS::setApiKey("sk_example_123456789");

$userManagement = new WorkOS\UserManagement();

$logoutUrl = $userManagement->getLogoutUrl(
    "session_01HQAG1HENBZMAZD82YRXDFC0B",
    return_to: "https://your-app.com/signed-out",
);
```

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

WorkOS workos = new WorkOS("sk_example_123456789");

String logoutUrl = workos.userManagement.getLogoutUrl(
    "session_01HQAG1HENBZMAZD82YRXDFC0B", "https://your-app.com/signed-out");
```

```txt language="url" title="Response" tab="2"
https://api.workos.com/user_management/sessions/logout?
session_id=session_01HQAG1HENBZMAZD82YRXDFC0B&return_to=https%3A%2F%your-app.com%2Fsigned-out
```

:::

### GET /user_management/sessions/logout

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `session_id` | string | Yes | The ID of the session that is ending. This can be extracted from the `sid` claim of the access token. |
| `return_to` | string | No | The URL to redirect the user to after logout. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `url` | string | The URL to redirect to. |