Skip to content

Commit 2c4dff6

Browse files
fix: added small fixes
1 parent a5045f4 commit 2c4dff6

File tree

7 files changed

+88
-46
lines changed

7 files changed

+88
-46
lines changed

auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This will intercept the tool call to initiate a CIBA request:
9393

9494
Next, add the following code to `src/lib/auth0.ts`:
9595

96-
```tsx src/lib/auth0.ts wrap lines highlight={2-5}
96+
```tsx src/lib/auth0.ts wrap lines highlight={12-20}
9797
//... existing code
9898
export const auth0 = new Auth0Client({
9999
authorizationParameters: {
@@ -118,7 +118,7 @@ export const getAccessToken = async () => {
118118

119119
Update the `/src/app/api/chat/[..._path]/route.ts` file with the following code. AccessToken will be passed to your LangGraph agent so we can use it from the Auth0 AI SDK to get the current user.
120120

121-
```ts src/app/api/chat/[..._path]/route.ts wrap lines highlight={3,10}
121+
```ts src/app/api/chat/[..._path]/route.ts wrap lines highlight={3,9-13}
122122
import { initApiPassthrough } from "langgraph-nextjs-api-passthrough";
123123

124124
import { getAccessToken } from "@/lib/auth0";
@@ -144,16 +144,16 @@ In your langgraph.json, add the path to your auth file:
144144
{
145145
"node_version": "20",
146146
"graphs": {
147-
"agent": "./agent.mts:graph"
147+
"agent": "./src/lib/agent.ts:agent"
148148
},
149149
"env": ".env",
150150
"auth": {
151-
"path": "./auth.mts:authHandler"
151+
"path": "./src/lib/auth.ts:authHandler"
152152
}
153153
}
154154
```
155-
Then, in your auth.mts file, add your auth logic:
156-
```typescript ./auth.mts wrap lines
155+
Then, in your auth.ts file, add your auth logic:
156+
```typescript ./src/lib/auth.ts wrap lines
157157
import { createRemoteJWKSet, jwtVerify } from "jose";
158158

159159
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -225,7 +225,13 @@ auth.authenticate(async (request: Request) => {
225225
...payload,
226226
};
227227
} catch (jwtError) {
228-
...
228+
console.log(
229+
"Auth0 JWT validation failed:",
230+
jwtError instanceof Error ? jwtError.message : "Unknown error"
231+
);
232+
throw new HTTPException(401, {
233+
message: "Invalid Authorization token provided.",
234+
});
229235
}
230236
}
231237
});
@@ -313,9 +319,9 @@ SHOP_API_AUDIENCE=sample-shop-api
313319

314320
### Require async authorization for your tool
315321

316-
Call the tool from your AI app to make purchases. Update the `src/lib/agent.ts` file with the following code:
322+
Call the tool from your AI app to make purchases. Update the `./src/lib/agent.ts` file with the following code:
317323

318-
```ts src/lib/agent.ts wrap lines highlight={2,3,9}
324+
```ts ./src/lib/agent.ts wrap lines highlight={2,3,9}
319325
//...
320326
import { withAsyncAuthorization } from "./auth0-ai";
321327
import { shopOnlineTool } from "./tools/shop-online";

auth4genai/snippets/get-started/langchain-next-js/auth-for-rag.mdx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const { GET, POST, PUT, PATCH, DELETE, OPTIONS, runtime } =
151151

152152
Next, add the following code to `src/lib/auth0.ts`:
153153

154-
```tsx src/lib/auth0.ts wrap lines highlight={14,25}
154+
```tsx src/lib/auth0.ts wrap lines highlight={13-21,23-26}
155155
import { Auth0Client } from '@auth0/nextjs-auth0/server';
156156

157157
export const auth0 = new Auth0Client({
@@ -189,16 +189,16 @@ In your langgraph.json, add the path to your auth file:
189189
{
190190
"node_version": "20",
191191
"graphs": {
192-
"agent": "./agent.mts:graph"
192+
"agent": "./src/lib/agent.ts:agent"
193193
},
194194
"env": ".env",
195195
"auth": {
196-
"path": "./auth.mts:authHandler"
196+
"path": "./src/lib/auth.ts:authHandler"
197197
}
198198
}
199199
```
200-
Then, in your auth.mts file, add your auth logic:
201-
```typescript ./auth.mts wrap lines
200+
Then, in your auth.ts file, add your auth logic:
201+
```typescript ./src/lib/auth.ts wrap lines
202202
import { createRemoteJWKSet, jwtVerify } from "jose";
203203

204204
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -270,17 +270,23 @@ auth.authenticate(async (request: Request) => {
270270
...payload,
271271
};
272272
} catch (jwtError) {
273-
...
273+
console.log(
274+
"Auth0 JWT validation failed:",
275+
jwtError instanceof Error ? jwtError.message : "Unknown error"
276+
);
277+
throw new HTTPException(401, {
278+
message: "Invalid Authorization token provided.",
279+
});
274280
}
275281
}
276282
});
277283

278284
export { auth as authHandler };
279285
```
280286

281-
Now, update the `/src/lib/agent.ts` file with the following code to add the tool to your agent:
287+
Now, update the `./src/lib/agent.ts` file with the following code to add the tool to your agent:
282288

283-
```ts src/lib/agent.ts wrap lines highlight={1,7}
289+
```ts ./src/lib/agent.ts wrap lines highlight={1,7}
284290
import { getContextDocumentsTool } from "./tools/context-docs";
285291

286292
//... existing code

auth4genai/snippets/get-started/langchain-next-js/call-others-api.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ In your langgraph.json, add the path to your auth file:
218218
{
219219
"node_version": "20",
220220
"graphs": {
221-
"agent": "./agent.mts:graph"
221+
"agent": "./src/lib/agent.ts:agent"
222222
},
223223
"env": ".env",
224224
"auth": {
225-
"path": "./auth.mts:authHandler"
225+
"path": "./src/lib/auth.ts:authHandler"
226226
}
227227
}
228228
```
229-
Then, in your auth.mts file, add your auth logic:
230-
```typescript ./auth.mts wrap lines
229+
Then, in your auth.ts file, add your auth logic:
230+
```typescript ./src/lib/auth.ts wrap lines
231231
import { createRemoteJWKSet, jwtVerify } from "jose";
232232

233233
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -299,7 +299,13 @@ auth.authenticate(async (request: Request) => {
299299
...payload,
300300
};
301301
} catch (jwtError) {
302-
...
302+
console.log(
303+
"Auth0 JWT validation failed:",
304+
jwtError instanceof Error ? jwtError.message : "Unknown error"
305+
);
306+
throw new HTTPException(401, {
307+
message: "Invalid Authorization token provided.",
308+
});
303309
}
304310
}
305311
});
@@ -331,7 +337,7 @@ export const gmailSearchTool = withGmailSearch(
331337
332338
Update your tool call to request an access token, as shown in the following example:
333339
334-
```ts src/lib/agent.ts wrap lines highlight={2,10-13}
340+
```ts ./src/lib/agent.ts wrap lines highlight={2,10-13}
335341
//...
336342
import { gmailSearchTool } from './tools/gmail-search';
337343

auth4genai/snippets/get-started/langchain-next-js/call-your-api.mdx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ In your langgraph.json, add the path to your auth file:
8383
{
8484
"node_version": "20",
8585
"graphs": {
86-
"agent": "./agent.mts:graph"
86+
"agent": "./src/lib/agent.ts:agent"
8787
},
8888
"env": ".env",
8989
"auth": {
90-
"path": "./auth.mts:authHandler"
90+
"path": "./src/lib/auth.ts:authHandler"
9191
}
9292
}
9393
```
94-
Then, in your auth.mts file, add your auth logic:
95-
```typescript ./auth.mts wrap lines
94+
Then, in your auth.ts file, add your auth logic:
95+
```typescript ./src/lib/auth.ts wrap lines
9696
import { createRemoteJWKSet, jwtVerify } from "jose";
9797

9898
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -164,7 +164,13 @@ auth.authenticate(async (request: Request) => {
164164
...payload,
165165
};
166166
} catch (jwtError) {
167-
...
167+
console.log(
168+
"Auth0 JWT validation failed:",
169+
jwtError instanceof Error ? jwtError.message : "Unknown error"
170+
);
171+
throw new HTTPException(401, {
172+
message: "Invalid Authorization token provided.",
173+
});
168174
}
169175
}
170176
});
@@ -213,9 +219,9 @@ export const getUserInfoTool = tool(
213219
214220
### Add the tool to the AI agent
215221
216-
The AI agent processes and runs the user's request through the AI pipeline, including the tool call. Update the `/src/lib/agent.ts` file to add the tool to the agent.
222+
The AI agent processes and runs the user's request through the AI pipeline, including the tool call. Update the `./src/lib/agent.ts` file to add the tool to the agent.
217223
218-
```ts src/lib/agent.ts wrap lines highlight={2,8}
224+
```ts ./src/lib/agent.ts wrap lines highlight={2,8}
219225
//...
220226
import { getUserInfoTool } from "./tools/user-info";
221227

auth4genai/snippets/how-tos/github/langgraph.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ In your langgraph.json, add the path to your auth file:
198198
{
199199
"node_version": "20",
200200
"graphs": {
201-
"agent": "./agent.mts:graph"
201+
"agent": "./src/lib/agent.ts:agent"
202202
},
203203
"env": ".env",
204204
"auth": {
205-
"path": "./auth.mts:auth"
205+
"path": "./src/lib/auth.ts:authHandler"
206206
}
207207
}
208208
```
209-
Then, in your auth.mts file, add your auth logic:
210-
```typescript ./auth.mts wrap lines
209+
Then, in your auth.ts file, add your auth logic:
210+
```typescript ./src/lib/auth.ts wrap lines
211211
import { createRemoteJWKSet, jwtVerify } from "jose";
212212

213213
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -279,7 +279,13 @@ auth.authenticate(async (request: Request) => {
279279
...payload,
280280
};
281281
} catch (jwtError) {
282-
...
282+
console.log(
283+
"Auth0 JWT validation failed:",
284+
jwtError instanceof Error ? jwtError.message : "Unknown error"
285+
);
286+
throw new HTTPException(401, {
287+
message: "Invalid Authorization token provided.",
288+
});
283289
}
284290
}
285291
});

auth4genai/snippets/how-tos/google-calendar/langgraph.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ In your langgraph.json, add the path to your auth file:
213213
{
214214
"node_version": "20",
215215
"graphs": {
216-
"agent": "./agent.mts:graph"
216+
"agent": "./src/lib/agent.ts:agent"
217217
},
218218
"env": ".env",
219219
"auth": {
220-
"path": "./auth.mts:auth"
220+
"path": "./src/lib/auth.ts:authHandler"
221221
}
222222
}
223223
```
224-
Then, in your auth.mts file, add your auth logic:
225-
```typescript ./auth.mts wrap lines
224+
Then, in your auth.ts file, add your auth logic:
225+
```typescript ./src/lib/auth.ts wrap lines
226226
import { createRemoteJWKSet, jwtVerify } from "jose";
227227

228228
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -294,7 +294,13 @@ auth.authenticate(async (request: Request) => {
294294
...payload,
295295
};
296296
} catch (jwtError) {
297-
...
297+
console.log(
298+
"Auth0 JWT validation failed:",
299+
jwtError instanceof Error ? jwtError.message : "Unknown error"
300+
);
301+
throw new HTTPException(401, {
302+
message: "Invalid Authorization token provided.",
303+
});
298304
}
299305
}
300306
});

auth4genai/snippets/how-tos/slack/langgraph.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const withAccessTokenForConnection = (connection: string, scopes: string[]) =>
3131
});
3232

3333
export const withSlack = withAccessTokenForConnection("sign-in-with-slack", ["channels:read", "groups:read"]);
34-
34+
3535
```
3636

3737
### 2. Integrate your tool with Slack
@@ -200,16 +200,16 @@ In your langgraph.json, add the path to your auth file:
200200
{
201201
"node_version": "20",
202202
"graphs": {
203-
"agent": "./agent.mts:graph"
203+
"agent": "./src/lib/agent.ts:agent"
204204
},
205205
"env": ".env",
206206
"auth": {
207-
"path": "./auth.mts:auth"
207+
"path": "./src/lib/auth.ts:authHandler"
208208
}
209209
}
210210
```
211-
Then, in your auth.mts file, add your auth logic:
212-
```typescript ./auth.mts wrap lines
211+
Then, in your auth.ts file, add your auth logic:
212+
```typescript ./src/lib/auth.ts wrap lines
213213
import { createRemoteJWKSet, jwtVerify } from "jose";
214214

215215
const { Auth, HTTPException } = require("@langchain/langgraph-sdk/auth");
@@ -281,7 +281,13 @@ auth.authenticate(async (request: Request) => {
281281
...payload,
282282
};
283283
} catch (jwtError) {
284-
...
284+
console.log(
285+
"Auth0 JWT validation failed:",
286+
jwtError instanceof Error ? jwtError.message : "Unknown error"
287+
);
288+
throw new HTTPException(401, {
289+
message: "Invalid Authorization token provided.",
290+
});
285291
}
286292
}
287293
});

0 commit comments

Comments
 (0)