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-18Lines changed: 34 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,12 +25,14 @@ The following steps outline how to generate a JWT token:
25
25
26
26
### JWT Token Scopes
27
27
28
-
The generated 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.
28
+
The generated 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
30
For example, it can be used to restrict which API endpoints the token can access.
31
31
32
32
<Note>
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.
33
+
As of writing, the only publicly scoped API endpoint is
34
+
https://api.vapi.ai//call/web, which is used for Web Call creation. All other
-**Payload**: The payload includes the `orgId`, representing the organization ID.
94
+
-**Payload**: The payload includes the `orgId` representing the organization ID and the `token` object with the scope of the token.
93
95
-**Key**: The private key is used to sign the token, ensuring its authenticity.
94
96
-**Options**: The `expiresIn` option specifies that the token will expire in 1 hour.
95
97
-**Token Generation**: The `generateJWT` function (a placeholder for the actual JWT generation method) creates the token using the provided payload, key, and options.
96
98
97
-
## Making an Authenticated API Request
99
+
## Usage (Making an Authenticated API Request)
98
100
99
-
Once the token is generated, you can use it to make authenticated API requests. The following steps outline how to make an authenticated request:
101
+
If you set the scope to `private`, you can use it to make authenticated API requests. The following steps outline how to make an authenticated request:
100
102
101
103
1.**Define the API Endpoint**: Specify the URL of the API you want to call.
102
104
2.**Set the Headers**: Include the `Content-Type` and `Authorization` headers in your request. The `Authorization` header should include the generated JWT token prefixed with `Bearer`.
@@ -106,10 +108,10 @@ Once the token is generated, you can use it to make authenticated API requests.
-**Headers**: The `Content-Type` is set to `application/json`, and the `Authorization` header includes the generated JWT token.
129
130
-**API Call**: The `fetchData` function makes an asynchronous GET request to the specified API endpoint and logs the response.
130
131
131
-
### Usage
132
+
### Usage (Web Client)
133
+
134
+
If you set the scope to `public`, you can use it to make authenticated API requests using the Vapi Web Client.
135
+
136
+
```
137
+
import Vapi from '@vapi-ai/web';
138
+
139
+
const vapi = new Vapi({
140
+
token: 'your-jwt-token',
141
+
});
142
+
143
+
vapi.start('your-assistant-id');
144
+
```
145
+
146
+
## Notes
132
147
133
-
With the generated token, you can authenticate API requests to any endpoint requiring authentication. The token will be valid for the duration specified in the options (1 hour in this case).
148
+
- With the generated token, you can authenticate API requests to any endpoint requiring authentication. The token will be valid for the duration specified in the options (1 hour in this case).
149
+
- If you don't specify `token` in the JWT payload, the token will be public.
0 commit comments