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

# Widgets

Widgets are React components that provide complete functionality for common enterprise app workflows.

## Generate a widget token

Generate a widget token for a user, optionally scoped to an organization. When an organization is specified, org-scoped widgets are enabled; omitting it issues a user-only token for widgets like `UserProfile` and `UserSecurity`.

:::code-group

```bash language="curl" title="Request" tab="1"
curl --request POST \
  --url "https://api.workos.com/widgets/token" \
  --header "Authorization: Bearer sk_example_123456789" \
  --header "Content-Type: application/json" \
  -d @- <<'BODY'
    {
        "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
        "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5",
        "scopes": [
            "widgets:users-table:manage"
        ]
    }
BODY
```

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

const workos = new WorkOS('sk_example_123456789');

const { token } = await workos.widgets.getToken({
  organizationId: 'org_01EHZNVPK3SFK441A1RGBFSHRT',
  userId: 'user_01EHZNVPK3SFK441A1RGBFSHRT',
  scopes: ['widgets:users-table:manage'],
});
```

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

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

WorkOS.client.widgets.create_token
```

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

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

client.widgets.create_token()
```

```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.Widgets().CreateToken(context.Background())
	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->widgets()->createToken();
```

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

WorkOS workos = new WorkOS("sk_example_123456789");

workos.widgets.createToken();
```

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

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

await client.Widgets.CreateTokenAsync();
```

```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
        .widgets()
        .create_token()
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InNlc3Npb24..."
}
```

:::

### POST /widgets/token

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `organization_id` | string | No | An [Organization](/reference/organization) identifier. |
| `user_id` | string | No | A [User](/reference/authkit/user) identifier. |
| `scopes` | ("widgets:users-table:manage" \| "widgets:domain-verification:manage" \| "widgets:sso:manage" \| ...)[] | No | Scopes to include in the widget token. If a user_id is provided, the requested scopes will be also be restricted to the permissions that the user has in the requested organization. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `token` | string | The widget session token. |