-
Notifications
You must be signed in to change notification settings - Fork 3
feat: call-others-api, Vercel AI + React SPA #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we follow the structure and patterns in other quickstarts like the vercel+next.js one for example
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
thanks for review @deepu105 🙇 , will reflect some updates shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some minor suggestions and questions
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
|
||
```bash wrap lines | ||
git clone https://github.com/auth0-lab/auth0-ai-js.git | ||
cd auth0-ai-js/examples/calling-apis/spa-with-backend-api/react-hono-ai-sdk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue with having this in the SDK repo example is that the example might change more frequently compared to the quickstart, so unless the same team is maintaining and ensuring compatibility, this will end up breaking the quickstart. For other quickstart we have the sample and starters hosted in auth0-samples/auth0-ai-samples repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @pmalouin. I'm not sure here.
We are a bit strapped for time w/ several evolving SDK updates now, and my thought is that it is known these SDKs will be changing in the future. Having those changes more local (closer to the core source) will likely make them easier to update. But you are right that, downside is some drift w/ additional quickstarts maintained downstream. Upside is more timely examples which more accurately reflect current platform. Something to consider more in the long-term as we start to consider Core SDKs sourced from auth0/auth0-auth-js as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can figure this out later
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
accessToken: async () => { | ||
// The access token provided by the SPA will be used in the Token Vault exchange for a Google Calendar access token. | ||
// This can provided by the SPA via the Authorization header and set in Hono's authContext. | ||
return global.authContext.accessToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with Hono so ignore if its a stupid question. Usually, we get this via auth0.getSession() from the SDK right, is that not preferred here? feels a bit weird setting token on global context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed here & raised it as well - i think we are planning to expose as a common middleware from auth0/auth0-hono or auth0/auth0-auth-js which makes this cleaner in the future.
Short answer -> we do not have a great solution in place in the core sdk's for this yet, and we will likely prefer the common auth0 libraries over using something like hono/jwk for performing the jwk validation. A few things have already been proposed for MCP servers and others, but nothing has been defined yet.
For now, i think we may be able to improve upon this and resemble something closer to the long term w/:
// Middleware to set auth context
export const setAuthContext = (authContext: AuthContext) => {
return async (c: Context, next: () => Promise<void>) => {
c.set('authContext', authContext);
await next();
};
};
// Updated tool wrapper that accepts context
export const createGoogleCalendarTool = (c: Context): ToolWrapper => {
const authContext = c.get('authContext') as AuthContext;
if (!authContext?.accessToken) {
throw new Error("Access token not available in auth context");
}
return auth0AI.withTokenForConnection({
accessToken: async () => authContext.accessToken,
subjectTokenType: SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN,
connection: process.env.GOOGLE_CONNECTION_NAME || "google-oauth2",
scopes: [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.events.readonly",
],
});
};
As we will be doing something similar to retrieve this token via the SPA's Auth header rather than server-side session (like in Next.js).
I can try to update this today and circle back here. The shape of the Core SDK has changed as well, but that is well outside of the current scope, and impacts many other things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened:
auth0-lab/auth0-ai-js#260
any concerns w/ this revised approach for now? Will go ahead and reflect here for now as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better
auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
Outdated
Show resolved
Hide resolved
d747757
to
3b04d84
Compare
3b04d84
to
24e6647
Compare
24e6647
to
7e4b25b
Compare
7e4b25b
to
26d36bc
Compare
BasedOnStyles = Vale | ||
Vale.Terms = NO | ||
Vale.Spelling = NO | ||
Vale.Repetition = NO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seeing some Vale spell check errors which makes me think this has not been fully configured for this project quite yet, but the action is enabled.
https://github.com/auth0/docs-v2/runs/48343533939
Likely a more comprehensive change to review all spelling warnings and ignores, so leaving this alone for now. Happy to follow a convention once established, but for now disabling those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya I was starting to wonder if its useful as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some batch commitable suggestions
auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Deepu K Sasidharan <[email protected]>
Description
This introduces a Vercel AI + React SPA tab to the "Call Other's APIs on User's Behalf" page.
see: auth0-lab/auth0-ai-js#254
References
https://auth0team.atlassian.net/browse/AIDX-97
Testing
Checklist