Skip to content

Commit 4ae4a83

Browse files
fix
1 parent 6fbe91a commit 4ae4a83

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

fern/customization/jwt-authentication.mdx

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,65 @@ Before you proceed, ensure you have the following:
1212

1313
- An environment that supports JWT generation and API calls (e.g., a programming language or framework)
1414
- An account with a service that requires JWT authentication
15-
- Environment variables set up for the necessary credentials (e.g., organization ID and Vapi API key, both can be found in your Vapi dashboard)
15+
- Environment variables set up for the necessary credentials (e.g., organization ID and private key, both can be found in your Vapi portal)
1616

1717
## Generating a JWT Token
1818

1919
The following steps outline how to generate a JWT token:
2020

2121
1. **Define the Payload**: The payload contains the data you want to include in the token. In this case, it includes an `orgId`.
22-
2. **Get a Vapi API Key**: A Vapi API key is used to sign the token. Ensure it is securely stored, often in environment variables.
22+
2. **Get the Private Key**: The private key (provided by Vapi) is used to sign the token. Ensure it is securely stored, often in environment variables.
2323
3. **Set Token Options**: Define options for the token, such as the expiration time (`expiresIn`).
2424
4. **Generate the Token**: Use a JWT library or built-in functionality to generate the token with the payload, key, and options.
2525

26-
### Creating a Vapi API Key
26+
### JWT Token Scopes
2727

28-
You can find your API keys in the Vapi dashboard. Head to the `ORG SETTINGS` section on the sidebar and click on the `API Keys` tab.
28+
A JWT token can have one of two scopes: `private` or `public`. The scope of the token will determine the actions that can be performed using the token.
2929

30-
By default, Vapi creates a pair of private and public API keys for you. However, you may create new API keys at any time through the dashboard or API.
31-
32-
<Frame>
33-
<img src="../static/images/quickstart/dashboard/vapi-api-keys-tab.png" />
34-
</Frame>
35-
36-
Creating new API keys is straightforward through the Vapi API.
37-
38-
**Example (creating a private API key):**
39-
40-
```bash
41-
curl -X POST 'https://api.vapi.ai/token' \
42-
-H 'Content-Type: application/json' \
43-
-H 'Authorization: Bearer <YOUR_API_KEY>' \
44-
-d '{
45-
"name": "My Private Vapi API Key",
46-
"tag": "private"
47-
}'
48-
```
49-
50-
**Example (creating a public API key):**
30+
For example, it can be used to restrict which API endpoints the token can access.
5131

5232
<Note>
53-
The **restrictions** field is optional. All fields besides **enabled** are only relevant for **public** tokens.
33+
As of writing, the only publicly scoped API endpoint is https://api.vapi.ai//call/web, which is used for Web Call creation. All other endpoints are privately scoped.
5434
</Note>
5535

56-
```bash
57-
curl -X POST 'https://api.vapi.ai/token' \
58-
-H 'Content-Type: application/json' \
59-
-H 'Authorization: Bearer <YOUR_API_KEY>' \
60-
-d '{
61-
"name": "My Public Vapi API Key",
62-
"tag": "public",
63-
"restrictions": {
64-
"enabled": true,
65-
"allowedOrigins": ["https://example.vapi.ai"],
66-
"allowedAssistantIds": ["1cbf8c70-5fd7-4f61-a220-376ab35be1b0"],
67-
"allowTransientAssistant": false,
68-
}
69-
}'
70-
```
36+
### Example (generating a private JWT token)
7137

72-
### Vapi API Key Scope
38+
```js
39+
// Define the payload
40+
const payload = {
41+
orgId: process.env.ORG_ID,
42+
};
7343

74-
A Vapi API Key can have one of two scopes: Private or Public. The scope of the key will determine the actions that can be performed using the key.
44+
const key = {
45+
tag: 'private',
46+
};
7547

76-
For example, it can be used to restrict which API endpoints the key can access.
48+
// Define token options
49+
const options = {
50+
expiresIn: '1h',
51+
};
7752

78-
<Note>
79-
As of writing, the only publicly scoped API endpoint is https://api.vapi.ai//call/web, which is used for Web Call creation. All other endpoints are privately scoped.
80-
</Note>
53+
// Generate the token using a JWT library or built-in functionality
54+
const token = generateJWT(payload, key, options);
55+
```
8156

82-
### Example
57+
### Example (generating a public JWT token)
8358

8459
```js
8560
// Define the payload
8661
const payload = {
8762
orgId: process.env.ORG_ID,
8863
};
8964

90-
// Get the private (or public) Vapi API key from environment variables
91-
const key = process.env.VAPI_API_KEY;
65+
const key = {
66+
tag: 'public',
67+
restrictions: {
68+
enabled: true,
69+
allowedOrigins: ['https://example.vapi.ai'],
70+
allowedAssistantIds: ['1cbf8c70-5fd7-4f61-a220-376ab35be1b0'],
71+
allowTransientAssistant: false,
72+
},
73+
};
9274

9375
// Define token options
9476
const options = {
@@ -102,7 +84,7 @@ const token = generateJWT(payload, key, options);
10284
### Explanation
10385

10486
- **Payload**: The payload includes the `orgId`, representing the organization ID.
105-
- **Key**: The Vapi API key is used to sign the token, ensuring its authenticity.
87+
- **Key**: The private key is used to sign the token, ensuring its authenticity.
10688
- **Options**: The `expiresIn` option specifies that the token will expire in 1 hour.
10789
- **Token Generation**: The `generateJWT` function (a placeholder for the actual JWT generation method) creates the token using the provided payload, key, and options.
10890

@@ -146,4 +128,4 @@ With the generated token, you can authenticate API requests to any endpoint requ
146128

147129
## Conclusion
148130

149-
This documentation covered the basics of generating a JWT token and demonstrated how to use the token to make authenticated API requests. Ensure that your environment variables (e.g., `ORG_ID` and ``VAPI_API_KEY``) are correctly set up before running the code.
131+
This documentation covered the basics of generating a JWT token and demonstrated how to use the token to make authenticated API requests. Ensure that your environment variables (e.g., `ORG_ID`) are correctly set up before running the code.

0 commit comments

Comments
 (0)