-
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
Open
priley86
wants to merge
10
commits into
main
Choose a base branch
from
calling-apis-react-hono-ai-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
866e691
feat: call-others-api, Vercel AI + React SPA
priley86 fa07281
fix: code review updates, refactored prereqs
priley86 5398b4f
chore: qualify Next.js example
priley86 19c9251
fix: update example reference
priley86 c4416a0
feat: revise FederatedConnectionPopup
priley86 80de2aa
feat: code review reflections
priley86 26d36bc
fix: add vale.ini
priley86 3e61e31
Apply suggestions from code review
priley86 ce6d61a
fix: tweaking api step, resource client step props
priley86 b866d5b
fix: remove <pre> tags around code block
priley86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MinAlertLevel = error | ||
|
||
[formats] | ||
mdx = md | ||
|
||
[*.mdx] | ||
BasedOnStyles = Vale | ||
Vale.Terms = NO | ||
Vale.Spelling = NO | ||
Vale.Repetition = NO | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
292 changes: 225 additions & 67 deletions
292
auth4genai/snippets/get-started/prerequisites/call-others-api.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,236 @@ | ||
/** | ||
* Prerequisites for call-others-api quickstarts. | ||
* @param {Object} props - The props object | ||
* | ||
* @param {Object|undefined} [props.createAuth0ApplicationStep] - Configuration for Auth0 application creation step | ||
* @param {string} [props.createAuth0ApplicationStep.applicationType] - Type of Auth0 application (e.g., "Regular Web") | ||
* @param {string} [props.createAuth0ApplicationStep.callbackUrl] - Allowed callback URL for the application | ||
* @param {string} [props.createAuth0ApplicationStep.logoutUrl] - Allowed logout URL for the application | ||
* | ||
* @param {string|undefined} [props.createAuth0ApplicationStep.allowedWebOrigins] - Allowed web origins for the application | ||
* | ||
* @param {Object|undefined} [props.refreshTokenGrantStep] - Configuration for refresh token grant step | ||
* @param {string} [props.refreshTokenGrantStep.applicationName] - Name of the application for refresh token grant | ||
* | ||
* @param {Object|undefined} [props.createAuth0ApiStep] - Configuration for Auth0 API creation step | ||
* | ||
* @param {Object|undefined} [props.createResourceServerClientStep] - Configuration for resource server client creation step | ||
* | ||
* @param {Object|undefined} [props.tokenExchangeGrantStep] - Configuration for token exchange grant step | ||
* @param {string} [props.tokenExchangeGrantStep.applicationName] - Name of the application for token exchange grant | ||
* | ||
* @returns {JSX.Element} A React component containing prerequisite steps | ||
*/ | ||
|
||
export const Prerequisites = ({ | ||
callbackUrl = "http://localhost:3000/auth/callback", | ||
logoutUrl = "http://localhost:3000", | ||
createAuth0ApplicationStep = { | ||
applicationType: "Regular Web", | ||
callbackUrl: "http://localhost:3000/auth/callback", | ||
logoutUrl: "http://localhost:3000", | ||
allowedWebOrigins: undefined, | ||
}, | ||
refreshTokenGrantStep = undefined, | ||
createAuth0ApiStep = undefined, | ||
createResourceServerClientStep = undefined, | ||
tokenExchangeGrantStep = undefined, | ||
}) => { | ||
// Build steps array dynamically based on conditions | ||
const steps = []; | ||
|
||
// Always include these steps | ||
steps.push( | ||
<Step key="auth0-account" title="Create an Auth0 Account and a Dev Tenant"> | ||
To continue with this quickstart, you need an{" "} | ||
<a | ||
href="https://auth0.com/signup?onboard_app=genai&ocid=7014z000001NyoxAAC-aPA4z0000008OZeGAM" | ||
target="_blank" | ||
> | ||
Auth0 account | ||
</a>{" "} | ||
and a Developer Tenant. | ||
</Step> | ||
); | ||
|
||
if (createAuth0ApplicationStep) { | ||
steps.push( | ||
<Step key="auth0-application" title="Create an Auth0 Application"> | ||
<a href="https://manage.auth0.com/dashboard" target="_blank"> | ||
Create and configure an Auth0 Application | ||
</a>{" "} | ||
with the following properties: | ||
<ul> | ||
<li> | ||
Type: <code>{createAuth0ApplicationStep.applicationType}</code> | ||
</li> | ||
<li> | ||
Allowed Callback URLs: <code>{createAuth0ApplicationStep.callbackUrl}</code> | ||
</li> | ||
<li> | ||
Allowed Logout URLs: <code>{createAuth0ApplicationStep.logoutUrl}</code> | ||
</li> | ||
{createAuth0ApplicationStep.allowedWebOrigins && ( | ||
<li> | ||
Allowed Web Origins: <code>{createAuth0ApplicationStep.allowedWebOrigins}</code> | ||
</li> | ||
)} | ||
</ul> | ||
To learn more about Auth0 applications, read{" "} | ||
<a | ||
href="https://auth0.com/docs/get-started/applications" | ||
target="_blank" | ||
> | ||
Applications | ||
</a> | ||
. | ||
</Step> | ||
); | ||
} | ||
// Conditionally add steps | ||
if (refreshTokenGrantStep) { | ||
steps.push( | ||
<Step key="refresh-token" title="Enable Refresh Token Grant"> | ||
Enable the Refresh Token Grant for your{" "} | ||
{refreshTokenGrantStep.applicationName}. Go to{" "} | ||
<strong> | ||
Applications > [Your Application] > Settings > Advanced > | ||
Grant Types | ||
</strong>{" "} | ||
and enable the <strong>Refresh Token</strong> grant type. | ||
</Step> | ||
); | ||
} | ||
|
||
if (createAuth0ApiStep) { | ||
steps.push( | ||
<Step key="auth0-api" title="Create an Auth0 API"> | ||
<ul> | ||
<li>In your Auth0 Dashboard, go to <strong>Applications > APIs</strong></li> | ||
<li>Create a new API with an identifier (audience)</li> | ||
<li>Once API is created, go to the APIs <strong>Settings > Access Settings</strong> and enable <strong>Allow Offline Access</strong></li> | ||
<li>Note down the API identifier for your environment variables</li> | ||
</ul> | ||
To learn more about Auth0 APIs, read{" "} | ||
<a | ||
href="https://auth0.com/docs/get-started/auth0-overview/set-up-apis" | ||
target="_blank" | ||
> | ||
APIs | ||
</a> | ||
. | ||
</Step> | ||
); | ||
} | ||
|
||
if (createResourceServerClientStep) { | ||
steps.push( | ||
<Step key="resource-server" title="Create a Resource Server Client"> | ||
This is a special client that allows your API server to perform token | ||
exchanges using{" "} | ||
<strong> | ||
<i>access tokens</i> | ||
</strong>{" "} | ||
instead of{" "} | ||
<strong> | ||
<i>refresh tokens</i> | ||
</strong> | ||
. This client enables Token Vault to exchange an access token for an | ||
external API access token (e.g., Google Calendar API). | ||
<br /> | ||
<br /> | ||
Create this client programmatically via the Auth0 Management API: | ||
|
||
<CodeBlock | ||
language="bash" | ||
expandable="true" | ||
lines="true" | ||
filename="Create Resource Server Client" | ||
> | ||
{`curl -L 'https://{tenant}.auth0.com/api/v2/clients' \\ | ||
-H 'Content-Type: application/json' \\ | ||
-H 'Accept: application/json' \\ | ||
-H 'Authorization: Bearer {MANAGEMENT_API_TOKEN}' \\ | ||
-d '{ | ||
"name": "Calendar API Resource Server Client", | ||
"app_type": "resource_server", | ||
"grant_types": ["urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token"], | ||
"resource_server_identifier": "YOUR_API_IDENTIFIER" | ||
}'`} | ||
</CodeBlock> | ||
|
||
<ul> | ||
<li> | ||
Note that your <code>MANAGEMENT_API_TOKEN</code> above must have the{" "} | ||
<code>create:clients</code> scope in order to create a new client. | ||
One way you can create a new token with this access is by doing the | ||
following: | ||
<ul> | ||
<li> | ||
Navigate to <strong>Applications > APIs > Auth0 Management API > API Explorer</strong> | ||
tab in your tenant | ||
</li> | ||
<li>Hit the <strong>Create & Authorize Test Application</strong> button</li> | ||
<li> | ||
Copy the jwt access token shown and provide it as the{" "} | ||
<code>MANAGEMENT_API_TOKEN</code> | ||
</li> | ||
</ul> | ||
</li> | ||
<li> | ||
Note down the <code>client_id</code> and <code>client_secret</code>{" "} | ||
returned from the curl response for your environment variables after running curl | ||
successfully. | ||
</li> | ||
</ul> | ||
</Step> | ||
); | ||
} | ||
|
||
if (tokenExchangeGrantStep) { | ||
steps.push( | ||
<Step key="token-exchange" title="Enable Token Exchange Grant"> | ||
Enable the Token Exchange Grant for your{" "} | ||
{tokenExchangeGrantStep.applicationName}. Go to{" "} | ||
<strong> | ||
Applications > [Your Application] > Settings > Advanced > | ||
Grant Types | ||
</strong>{" "} | ||
and enable the <strong>Token Exchange</strong> grant type. | ||
</Step> | ||
); | ||
} | ||
|
||
// Always include these final steps | ||
steps.push( | ||
<Step key="google-connection" title="Configure Google Social Connection"> | ||
Set up a Google developer account that allows for third-party API calls | ||
following the{" "} | ||
<a href="/guides/google-sign-in-and-auth"> | ||
Google Sign-in and Authorization | ||
</a>{" "} | ||
instructions. | ||
</Step> | ||
); | ||
|
||
steps.push( | ||
<Step key="openai" title="OpenAI Platform"> | ||
Set up an{" "} | ||
<a | ||
href="https://platform.openai.com/docs/libraries#create-and-export-an-api-key" | ||
target="_blank" | ||
> | ||
OpenAI account and API key | ||
</a> | ||
. | ||
</Step> | ||
); | ||
|
||
return ( | ||
<> | ||
<Heading level={3} id="prerequisites"> | ||
Prerequisites | ||
</Heading> | ||
Before getting started, make sure you have completed the following steps: | ||
<Steps> | ||
<Step title="Create an Auth0 Account and a Dev Tenant"> | ||
To continue with this quickstart, you need an{" "} | ||
<a | ||
href="https://auth0.com/signup?onboard_app=genai&ocid=7014z000001NyoxAAC-aPA4z0000008OZeGAM" | ||
target="_blank" | ||
> | ||
Auth0 account | ||
</a>{" "} | ||
and a Developer Tenant. | ||
</Step> | ||
<Step title="Create an Auth0 Application"> | ||
<a href="https://manage.auth0.com/dashboard" target="_blank"> | ||
Create and configure an Auth0 Application | ||
</a>{" "} | ||
with the following properties: | ||
<ul> | ||
<li> | ||
Type: <code>Regular Web</code> | ||
</li> | ||
<li> | ||
Allowed Callback URLs: <code>{callbackUrl}</code> | ||
</li> | ||
<li> | ||
Allowed Logout URLs: <code>{logoutUrl}</code> | ||
</li> | ||
</ul> | ||
To learn more about Auth0 applications, read{" "} | ||
<a | ||
href="https://auth0.com/docs/get-started/applications" | ||
target="_blank" | ||
> | ||
Applications | ||
</a> | ||
. | ||
</Step> | ||
<Step title="Enable Token Exchange Grant"> | ||
Enable the Token Exchange Grant for your Auth0 Application. Go to{" "} | ||
<strong> | ||
Applications > [Your Application] > Settings > Advanced | ||
> Grant Types | ||
</strong>{" "} | ||
and enable the <strong>Token Exchange</strong> grant type. | ||
</Step> | ||
|
||
<Step title="Configure Google Social Connection"> | ||
Set up a Google developer account that allows for third-party API | ||
calls following the{" "} | ||
<a href="/guides/google-sign-in-and-auth"> | ||
Google Sign-in and Authorization | ||
</a>{" "} | ||
instructions. | ||
</Step> | ||
|
||
<Step title="OpenAI Platform"> | ||
Set up an{" "} | ||
<a | ||
href="https://platform.openai.com/docs/libraries#create-and-export-an-api-key" | ||
target="_blank" | ||
> | ||
OpenAI account and API key | ||
</a> | ||
. | ||
</Step> | ||
</Steps> | ||
<Steps>{steps}</Steps> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.