You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/customization/jwt-authentication.mdx
+34-52Lines changed: 34 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,83 +12,65 @@ Before you proceed, ensure you have the following:
12
12
13
13
- An environment that supports JWT generation and API calls (e.g., a programming language or framework)
14
14
- 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)
16
16
17
17
## Generating a JWT Token
18
18
19
19
The following steps outline how to generate a JWT token:
20
20
21
21
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.
23
23
3.**Set Token Options**: Define options for the token, such as the expiration time (`expiresIn`).
24
24
4.**Generate the Token**: Use a JWT library or built-in functionality to generate the token with the payload, key, and options.
25
25
26
-
### Creating a Vapi API Key
26
+
### JWT Token Scopes
27
27
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.
29
29
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.
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.
51
31
52
32
<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.
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
+
constkey= {
45
+
tag:'private',
46
+
};
75
47
76
-
For example, it can be used to restrict which API endpoints the key can access.
48
+
// Define token options
49
+
constoptions= {
50
+
expiresIn:'1h',
51
+
};
77
52
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
+
consttoken=generateJWT(payload, key, options);
55
+
```
81
56
82
-
### Example
57
+
### Example (generating a public JWT token)
83
58
84
59
```js
85
60
// Define the payload
86
61
constpayload= {
87
62
orgId:process.env.ORG_ID,
88
63
};
89
64
90
-
// Get the private (or public) Vapi API key from environment variables
-**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.
106
88
-**Options**: The `expiresIn` option specifies that the token will expire in 1 hour.
107
89
-**Token Generation**: The `generateJWT` function (a placeholder for the actual JWT generation method) creates the token using the provided payload, key, and options.
108
90
@@ -146,4 +128,4 @@ With the generated token, you can authenticate API requests to any endpoint requ
146
128
147
129
## Conclusion
148
130
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