Skip to content

Manage OAuth Redirects from the CLI (#2603) [bump to v1.0.20]#2603

Merged
drew-harris merged 6 commits into
mainfrom
drewh/oauth-redirect-manage
Apr 27, 2026
Merged

Manage OAuth Redirects from the CLI (#2603) [bump to v1.0.20]#2603
drew-harris merged 6 commits into
mainfrom
drewh/oauth-redirect-manage

Conversation

@drew-harris
Copy link
Copy Markdown
Contributor

@drew-harris drew-harris commented Apr 24, 2026

Adds commands for managing Oauth redirects in the CLI.
Uses the same "add" "list" "delete" structure as how to manage clients.

Tests were written by AI to match the same pattern as the auth client tests

instant-cli auth origin add --help
instant-cli auth origin add --yes --type website --url drewh.net
instant-cli auth origin add --yes --type vercel --project test-project
instant-cli auth origin add --yes --type custom-scheme --scheme myapp://
instant-cli auth origin add --yes --type netlify --site test-site
instant-cli auth origin list
instant-cli auth origin delete
instant-cli auth origin delete --yes --id <ORIGIN_ID>

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cd73c4c2-44df-459f-a604-2d5bc3105720

📥 Commits

Reviewing files that changed from the base of the PR and between 88f853e and 998ca5b.

📒 Files selected for processing (1)
  • client/packages/version/src/version.ts
✅ Files skipped from review due to trivial changes (1)
  • client/packages/version/src/version.ts

📝 Walkthrough

Walkthrough

Adds CLI subcommands to manage authorized redirect origins (list, add, delete), HTTP client helpers for adding/removing origins, comprehensive CLI tests, and updates server-side authorization for creating origins to require :apps/write scope.

Changes

Cohort / File(s) Summary
Auth Origin Commands
client/packages/cli/src/commands/auth/origin/add.ts, client/packages/cli/src/commands/auth/origin/delete.ts, client/packages/cli/src/commands/auth/origin/list.ts
New CLI implementations: add validates types (website, netlify, vercel, custom-scheme), prompts or errors on missing args, posts origin; delete supports --id or interactive selection and confirms deletion; list prints human-readable or JSON output.
CLI Integration
client/packages/cli/src/index.ts
Registers auth origin subcommands (list, add, delete) wired through runCommandEffect with app-layer options and JSON output silencing for list.
HTTP OAuth Helpers
client/packages/cli/src/lib/oauth.ts
Adds AuthorizedOriginResponse schema plus addAuthorizedOrigin and removeAuthorizedOrigin Effect-based HTTP calls that post/delete origins for the current app and decode responses.
Tests
client/packages/cli/__tests__/authOriginManagement.test.ts
Comprehensive Vitest suite mocking CLI/UI/OAuth flows; tests add/list/delete behaviors, interactive prompts, JSON output, and error conditions.
Server Authorization
server/src/instant/dash/routes.clj
Creation handler now uses req->app-accepting-superadmin-or-ref-token! with :apps/write scope instead of collaborator-level auth.
Version Bump
client/packages/version/src/version.ts
Package version updated from v1.0.19 to v1.0.20.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI (auth origin add)
    participant HTTP as CLI HTTP helper
    participant Server as Server API
    participant DB as Database

    CLI->>HTTP: addAuthorizedOrigin({service, params})
    HTTP->>Server: POST /apps/:appId/authorized-redirect-origins {service, params} (auth token)
    Server->>Server: authorize via req->app-accepting-superadmin-or-ref-token! (:apps/write)
    Server->>DB: persist authorized redirect origin
    DB-->>Server: persisted origin with id
    Server-->>HTTP: 200 { origin }
    HTTP-->>CLI: decoded AuthorizedOriginResponse
    CLI-->>CLI: log confirmation (display, type, id)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • stopachka
  • dwwoelfel
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Manage OAuth Redirects from the CLI' directly describes the main feature added: CLI commands for managing OAuth redirect origins.
Description check ✅ Passed The description clearly explains that the PR adds commands for managing OAuth redirects in the CLI using add/list/delete structure and mentions tests were written to match the auth client pattern.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch drewh/oauth-redirect-manage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

View Vercel preview at instant-www-js-drewh-oauth-redirect-manage-jsv.vercel.app.

@drew-harris drew-harris force-pushed the drewh/oauth-redirect-manage branch from 1fe5f55 to bf0db74 Compare April 27, 2026 16:51
Base automatically changed from drewh/cli-links to main April 27, 2026 17:00
@drew-harris drew-harris force-pushed the drewh/oauth-redirect-manage branch from bf0db74 to 4e7707a Compare April 27, 2026 17:00
@drew-harris drew-harris changed the title (ignore) Manage OAuth Redirects from the CLI Apr 27, 2026
@drew-harris drew-harris force-pushed the drewh/oauth-redirect-manage branch from a3a51d3 to 88f853e Compare April 27, 2026 20:29
@drew-harris drew-harris marked this pull request as ready for review April 27, 2026 20:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
client/packages/cli/src/commands/auth/origin/delete.ts (1)

22-49: Optional: collapse the two if blocks into if/else and consider mirroring add.ts's BadArgsError handling.

The two if (!opts.id) and if (opts.id) branches are mutually exclusive but currently duplicate the removeAuthorizedOrigin call and rely on fall-through; an if/else makes the intent obvious and is friendlier to future edits.

Separately, add.ts wraps its body with Effect.catchTag('BadArgsError', ...) to log the error message plus a --help hint. Here, the Must specify --id error escapes as a runPromise rejection (the test relies on it via rejects.toThrow). If you want consistent UX between auth origin add and auth origin delete failures, consider applying the same catchTag (and updating the test to assert on logged output instead of a thrown rejection).

♻️ Proposed if/else refactor (drop-in)
-  if (!opts.id) {
-    const { yes } = yield* GlobalOpts;
-    if (yes) {
-      return yield* BadArgsError.make({
-        message: 'Must specify --id',
-      });
-    }
-
-    const picked = yield* runUIEffect(
-      new UI.Select({
-        options: origins.map((origin) => ({
-          label:
-            `${originSource(origin)} — ${originDisplay(origin)} ` +
-            chalk.dim(`(${origin.id})`),
-          value: origin,
-        })),
-        promptText: 'Select an origin to delete:',
-      }),
-    );
-
-    yield* removeAuthorizedOrigin(picked.id);
-  }
-
-  if (opts.id) {
-    yield* removeAuthorizedOrigin(opts.id);
-  }
+  let targetId: string;
+  if (opts.id) {
+    targetId = opts.id;
+  } else {
+    const { yes } = yield* GlobalOpts;
+    if (yes) {
+      return yield* BadArgsError.make({ message: 'Must specify --id' });
+    }
+    const picked = yield* runUIEffect(
+      new UI.Select({
+        options: origins.map((origin) => ({
+          label:
+            `${originSource(origin)} — ${originDisplay(origin)} ` +
+            chalk.dim(`(${origin.id})`),
+          value: origin,
+        })),
+        promptText: 'Select an origin to delete:',
+      }),
+    );
+    targetId = picked.id;
+  }
+
+  yield* removeAuthorizedOrigin(targetId);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/packages/cli/src/commands/auth/origin/delete.ts` around lines 22 - 49,
Collapse the two mutually exclusive branches into a single if/else: if
(!opts.id) run the GlobalOpts/interactive picker (runUIEffect with UI.Select)
and call removeAuthorizedOrigin(picked.id) in the if branch, else call
removeAuthorizedOrigin(opts.id) in the else branch; keep the existing
BadArgsError.make usage when yes is set. Then wrap the command's Effect pipeline
with Effect.catchTag('BadArgsError', ...) mirroring auth origin add: catch the
BadArgsError and log its message plus a short hint to run --help (so failures
are logged instead of bubbling as a rejected promise). Ensure you reference the
same symbols: removeAuthorizedOrigin, GlobalOpts, runUIEffect/UI.Select,
BadArgsError, and Effect.catchTag.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@client/packages/cli/src/commands/auth/origin/delete.ts`:
- Around line 22-49: Collapse the two mutually exclusive branches into a single
if/else: if (!opts.id) run the GlobalOpts/interactive picker (runUIEffect with
UI.Select) and call removeAuthorizedOrigin(picked.id) in the if branch, else
call removeAuthorizedOrigin(opts.id) in the else branch; keep the existing
BadArgsError.make usage when yes is set. Then wrap the command's Effect pipeline
with Effect.catchTag('BadArgsError', ...) mirroring auth origin add: catch the
BadArgsError and log its message plus a short hint to run --help (so failures
are logged instead of bubbling as a rejected promise). Ensure you reference the
same symbols: removeAuthorizedOrigin, GlobalOpts, runUIEffect/UI.Select,
BadArgsError, and Effect.catchTag.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4714d53e-9dc6-4cb9-8922-5f8fb480d949

📥 Commits

Reviewing files that changed from the base of the PR and between fb3a065 and 88f853e.

📒 Files selected for processing (7)
  • client/packages/cli/__tests__/authOriginManagement.test.ts
  • client/packages/cli/src/commands/auth/origin/add.ts
  • client/packages/cli/src/commands/auth/origin/delete.ts
  • client/packages/cli/src/commands/auth/origin/list.ts
  • client/packages/cli/src/index.ts
  • client/packages/cli/src/lib/oauth.ts
  • server/src/instant/dash/routes.clj

Copy link
Copy Markdown
Contributor

@stopachka stopachka left a comment

Choose a reason for hiding this comment

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

SGTM!

@drew-harris drew-harris changed the title Manage OAuth Redirects from the CLI Manage OAuth Redirects from the CLI (#2603) [bump to v1.0.20] Apr 27, 2026
@drew-harris drew-harris merged commit db72789 into main Apr 27, 2026
28 checks passed
@drew-harris drew-harris deleted the drewh/oauth-redirect-manage branch April 27, 2026 21:23
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