Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

priley86
Copy link

@priley86 priley86 commented Aug 12, 2025

Description

This introduces a Vercel AI + React SPA tab to the "Call Other's APIs on User's Behalf" page.

Screenshot 2025-08-12 at 6 41 51 PM

see: auth0-lab/auth0-ai-js#254

References

https://auth0team.atlassian.net/browse/AIDX-97

Testing

Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Also include details of the environment this PR was developed in (language/platform/browser version).

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

Copy link
Contributor

@deepu105 deepu105 left a 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

@priley86
Copy link
Author

thanks for review @deepu105 🙇 , will reflect some updates shortly.

@priley86
Copy link
Author

priley86 commented Aug 14, 2025

Copy link
Contributor

@deepu105 deepu105 left a 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


```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
Copy link
Contributor

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

Copy link
Author

@priley86 priley86 Aug 18, 2025

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.

Copy link
Contributor

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

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;
Copy link
Contributor

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

Copy link
Author

@priley86 priley86 Aug 18, 2025

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.

Copy link
Author

@priley86 priley86 Aug 18, 2025

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...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better

BasedOnStyles = Vale
Vale.Terms = NO
Vale.Spelling = NO
Vale.Repetition = NO
Copy link
Author

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.

Copy link
Contributor

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.

deepu105
deepu105 previously approved these changes Aug 19, 2025
Copy link
Contributor

@deepu105 deepu105 left a 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

Co-authored-by: Deepu K Sasidharan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants