-
Notifications
You must be signed in to change notification settings - Fork 9
fix(auth): make the CLI OAuth flow work — broker Firestore bug + missing website authorize page #379
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
Closed
Closed
fix(auth): make the CLI OAuth flow work — broker Firestore bug + missing website authorize page #379
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
775d4fb
fix(auth): make the CLI OAuth flow actually work — broker Firestore b…
jwaldrip ee05556
fix(auth): address review — gcp-build for GCF, no localStorage on CLI…
jwaldrip a5fa12a
fix(auth): server-side provider callback — match the OAuth app's regi…
jwaldrip e588301
Revert "fix(auth): server-side provider callback — match the OAuth ap…
jwaldrip 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,3 @@ | ||
| node_modules | ||
| dist | ||
|
jwaldrip marked this conversation as resolved.
|
||
| .tmp | ||
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
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
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,88 @@ | ||
| "use client" | ||
|
|
||
| import { useEffect, useState } from "react" | ||
| import { getAuthConfig, startCliOAuthFlow } from "@/lib/browse/auth" | ||
|
|
||
| // Reads the broker's CLI-session params from the URL and starts the provider | ||
| // OAuth. On success this immediately redirects to the provider, so the only | ||
| // rendered state the user normally sees is the brief "redirecting" spinner — | ||
| // the error state shows when the params are bad or the provider isn't | ||
| // OAuth-configured. | ||
| export function AuthorizeClient() { | ||
| const [error, setError] = useState<string | null>(null) | ||
|
|
||
| useEffect(() => { | ||
| const q = new URLSearchParams(window.location.search) | ||
| const host = q.get("host") || "" | ||
| const state = q.get("state") || "" | ||
| const provider = q.get("provider") || "" | ||
|
|
||
|
jwaldrip marked this conversation as resolved.
|
||
| if (!state || !host) { | ||
| setError("Missing or invalid CLI session (no state/host in the link).") | ||
| return | ||
| } | ||
| const config = getAuthConfig(host) | ||
| if (!config) { | ||
| setError( | ||
| `No OAuth client configured for ${host}. The site is missing the ${provider || "provider"} client id.`, | ||
| ) | ||
| return | ||
| } | ||
| // The broker declares the provider in the URL; `host` is the authoritative | ||
| // signal we actually resolve against. If they disagree, the broker URL is | ||
| // misconfigured — catch it here instead of redirecting to the wrong place. | ||
| if (provider && config.provider !== provider) { | ||
| setError( | ||
|
jwaldrip marked this conversation as resolved.
|
||
| `Provider mismatch: the link says ${provider} but host ${host} resolves to ${config.provider}.`, | ||
| ) | ||
| return | ||
| } | ||
| // Redirects the browser to the provider's authorize page. | ||
| startCliOAuthFlow(config, state) | ||
| }, []) | ||
|
|
||
| return ( | ||
| <div className="mx-auto max-w-md px-4 py-20 text-center"> | ||
| {error ? ( | ||
| <> | ||
| <h1 className="mb-2 text-xl font-bold">Couldn't start sign-in</h1> | ||
| <p className="text-sm text-red-600 dark:text-red-400">{error}</p> | ||
| <p className="mt-4 text-sm text-stone-500"> | ||
| Return to your terminal and try <code>haiku_auth_login</code> again. | ||
| </p> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <div className="mb-4"> | ||
| <svg | ||
| className="mx-auto h-12 w-12 animate-spin text-teal-500" | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| role="img" | ||
| aria-label="Loading" | ||
| > | ||
| <title>Loading</title> | ||
| <circle | ||
| className="opacity-25" | ||
| cx="12" | ||
| cy="12" | ||
| r="10" | ||
| stroke="currentColor" | ||
| strokeWidth="4" | ||
| /> | ||
| <path | ||
| className="opacity-75" | ||
| fill="currentColor" | ||
| d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| <h1 className="text-xl font-bold">Redirecting to sign in…</h1> | ||
| <p className="mt-2 text-sm text-stone-500"> | ||
| Authorizing the H·AI·K·U CLI for your Git provider. | ||
| </p> | ||
| </> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
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 @@ | ||
| import { AuthorizeClient } from "./AuthorizeClient" | ||
|
|
||
| // The haikumethod.ai broker's `/cli/start` points the CLI's verification_url | ||
| // here: /oauth/cli/authorize?provider=&host=&state=&authorize_via=. This page | ||
| // kicks off the provider OAuth (reusing the registered /auth/{provider}/callback/ | ||
| // redirect) carrying the broker `state`, so the callback can hand the exchanged | ||
| // token back to the broker's /cli/complete. Client-only (static export). | ||
| export default function CliAuthorizePage() { | ||
| return <AuthorizeClient /> | ||
| } |
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,32 @@ | ||
| // Terminal page of the CLI OAuth flow. The callback has already handed the | ||
| // token to the broker's /cli/complete; the polling CLI will pick it up. Nothing | ||
| // to do here but tell the human they can close the tab. | ||
| export default function CliDonePage() { | ||
| return ( | ||
| <div className="mx-auto max-w-md px-4 py-20 text-center"> | ||
| <div className="mb-4 text-green-500"> | ||
| <svg | ||
| className="mx-auto h-12 w-12" | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| stroke="currentColor" | ||
| role="img" | ||
| aria-label="Success" | ||
| > | ||
| <title>Success</title> | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth={2} | ||
| d="M5 13l4 4L19 7" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| <h1 className="mb-2 text-xl font-bold">You're signed in</h1> | ||
| <p className="text-stone-500"> | ||
| The H·AI·K·U CLI has your authorization. You can close this tab and | ||
| return to your terminal. | ||
| </p> | ||
| </div> | ||
| ) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.