Skip to content

feat: edit an OAuth2 app's redirect URIs as an ordered list - #29603

Merged
BobbyHo merged 75 commits into
mainfrom
plat-619-3-form
Sep 23, 2026
Merged

BobbyHo merged 75 commits into
mainfrom
plat-619-3-form

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Third of three in PLAT-619. #29440 made redirect_uris the source of truth in the database. #29502 added it to the admin API. This PR replaces the single callback URL field in the web UI with an editable list.

PR What it does
#29440 Backfill the list, read only from it, write both columns together, validate and cap every entry.
#29502 Accept and return redirect_uris on the admin API. Mark callback_url deprecated.
this Edit the list in the admin UI.
  • Replace the callback URL field with a list of redirect URIs, one row each, first row labeled "Default callback".
  • Add, edit, and remove rows; at least one is required, up to 32 allowed.
  • Show a +N badge on the applications table when an app has more than one redirect URI.
  • Drop omitempty on the request's redirect_uris field so an explicit empty list reaches the server.
  • Add tests and stories for edit, remove, add, and the minimum-one-entry case.

Stack: #29440, then #29502 (this branch is based on it), then this PR.

Sample Screen Captures:
image

image

Manual Tests

Scenario summary, all 24
# Scenario Result
1 Workspace up, PR checked out, dev server with the provider flag, tunnel; empty apps table Pass
2 Seed one DCR app with two redirect URIs, for section 4 Pass
3 Create form default state: one required "Default callback" row, Create disabled Pass
4 Create form: add/remove rows renumber correctly, other rows' values untouched Pass
5 Create form: removing the last row shows "At least one redirect URI is required.", Create stays disabled Pass
6 Create form: 32-row cap disables "Add redirect URI"; no list-level cap message merely for being at the cap Pass
7 Create form: byte-length validation (2049+ byte URI shows the byte-length message on that row only) Not run
8 Create form: shape validation for a confidential client (8 cases: loopback, .localhost, custom scheme, OOB URN, javascript:, malformed) Pass
9 Create form: duplicate URI flags only the second occurrence, doesn't silently drop it Pass
10 Create form: submit creates the app, navigates to the edit page with the "created" banner Pass
11 Edit form: pre-population matches redirect_uris order exactly, first row stays "Default callback" Pass
12 Edit form: "Update application" stays disabled until a field is actually edited Pass
13 Edit form: removing the last row shows the same required-message behavior as the create form Pass
14 Edit form: submit persists the list and order; API, edit-page reload, and applications table all agree Pass
15 Edit form: unsaved-changes prompt on navigating away with a dirty form; no prompt when clean Pass
16 Applications table: no badge at 1 URI, +1 (singular aria-label) at 2, +N (plural) at 3+ Pass
17 Applications table: badge tooltip content matches redirect_uris.slice(1).join("\n") Pass
18 DCR (public) app edit form: loopback-only description text; .localhost refused (unlike a confidential app); plain loopback still accepted Pass
19 DCR app edit form: #fragment and mailto: refused Pass (see note)
20 Keyboard: Tab/Shift+Tab/Enter/Space reach and operate every redirect-URI row, Remove button, and "Add redirect URI"; no trap among them Pass (see note)
21 Accessible names: each Remove button's name renumbers to match its current row, not a stale index Pass
22 Icon field regression check: clearing the icon and saving clears the stored value, not left unchanged Pass
23 Cleanup: delete every app created during this run Pass
24 Cleanup: DCR flag restored to its pre-run value Pass

Scenario 7 (byte-length validation) was not run this pass. Two accessibility
issues were found and are pre-existing, not introduced by this PR — see the
notes under scenarios 19-20 and the summary below the table.

Setup and verification commands

Run against the dev server through a coder port-forward ... --tcp 3000:3000 --tcp 8080:8080 tunnel. The dashboard (:8080) is where every
scenario below is actually driven from a browser; curl/ssh are used only
for the setup and verification calls shown in each scenario, reading the
session token from inside the workspace:

BASE_URL=http://localhost:3000
TOKEN=$(ssh dev.<workspace> 'cat ~/coder/.coderv2/session')
curl -s -X PUT "$BASE_URL/api/v2/oauth2-provider/apps/<id>" \
  -H "Coder-Session-Token: $TOKEN" -H 'Content-Type: application/json' \
  -d '<json body>'
1. Prerequisites

Dev server built from the PR branch with CODER_OAUTH2_PROVIDER_ENABLE=true;
buildinfo confirmed oauth2_provider:true. Dashboard loaded with an empty
apps table (fresh database).

Seeded one DCR app for section 4, noting the DCR flag's starting value
first so it can be restored in cleanup:

GET  /api/v2/oauth2-provider/settings          -> dynamic_client_registration_enabled: false  (starting value, noted)
PUT  /api/v2/oauth2-provider/settings           -> dynamic_client_registration_enabled: true
POST /oauth2/register {"redirect_uris":["http://localhost:9876/callback","http://localhost:9877/alt"], ...}
  -> HTTP 201, redirect_uris echoes both URIs, client_id saved

Applications table then showed one row, plat619-form-dcr, callback column
http://localhost:9876/callback plus a +1 badge — an early look at
scenario 16 already working.

2-9. Create form

Default state (/deployment/oauth2-provider/apps/add): one row labeled
"Default callback", empty, required; description text is the
confidential-client copy; "Create application" disabled.

Add/remove: filling row 1 and clicking "Add redirect URI" twice produced
"Redirect URI 2" and "Redirect URI 3"; removing the old row 2 renumbered the
remaining row to "Redirect URI 2" and left row 1's value untouched.

Removing the last (only) row: list becomes empty, "At least one redirect
URI is required." shown, "Create application" stays disabled.

32-row cap: "Add redirect URI" disables at exactly 32 rows. No list-level
cap message appears merely for being at the cap (the two red messages
visible are the ordinary per-row "Please enter a valid redirect URI." on
the two empty rows added last, unrelated to the cap) — there's no UI path
to a 33rd row to exercise the list-level max-count message.

Shape validation (confidential client), one row at a time:

http://example.com/callback       -> refused  (non-loopback http)
http://localhost:9876/callback    -> accepted (loopback)
http://app.localhost/callback     -> accepted (confidential .localhost allowance)
https://example.com/callback      -> accepted
myapp://callback                  -> accepted (custom scheme)
urn:ietf:wg:oauth:2.0:oob         -> accepted (OOB URN)
javascript:alert(1)               -> refused
not a url                         -> refused

Duplicate URI: entering the same valid URI in two rows flags only the
second occurrence ("This redirect URI is already used by another row.");
the first occurrence shows no error and the value isn't silently dropped.

Submit: naming the app and providing a single valid URI, then clicking
"Create application", navigated to
/deployment/oauth2-provider/apps/<id>?created=true with the "Your OAuth2
application has been created..." banner and a client ID. The success toast
itself wasn't caught in a screenshot (auto-dismissed before the
post-navigation capture); the navigation and banner outcome it precedes
was confirmed directly, so this wasn't re-tested.

Byte-length validation (a 2049+ byte URI on one row) was not run this
pass.

10-14. Edit form

Pre-population and ordering: an app was given three redirect_uris directly
via the API (bypassing the UI, since the app created above had only one
URI and wouldn't exercise ordering) —

PUT .../apps/<id> {"redirect_uris":["callback","second","third"], ...} -> 200

Reloading the edit page showed all three rows in that exact order, first
row still labeled "Default callback".

Update-disabled-until-dirty: on a clean load, "Update application" is
disabled. Appending a character to a row's value enables it; reverting the
character (without submitting) leaves nothing persisted.

Removing the last row on a populated edit form: removing all three rows one
at a time reproduces the create form's behavior exactly — "At least one
redirect URI is required." shown, Update disabled. Not submitted; page
reloaded afterward to discard.

Submit persists the list and order: reduced to one row, added a second via
"Add redirect URI" (confirming no drag/reorder control exists on any row —
just a text input and an "×" remove button), then "Update application".
Verified via the API, the edit-page reload, and the applications table, all
three agree on the persisted order and the resulting +1 badge. The
success toast wasn't caught in a screenshot here either, for the same
reason as the create-form submit above; persistence was confirmed directly
against the API instead of relying on the toast.

Unsaved-changes prompt: editing a field then clicking "Back to
applications" shows the "Unsaved changes" dialog ("Your updates haven't
been saved. Leave anyway?"). Cancel stays on the page with the edit intact;
Confirm navigates away and discards it (confirmed via reload). Repeating
with no edits made navigates away with no dialog.

15-16. Applications table badge

Needed one app at each of 1, 2, and 3+ URIs to exercise every branch. Set
up via the API (one fresh 1-URI app; bumped an existing app to 3 URIs),
then read the actual aria-label/title attributes from the DOM rather
than relying on the visual badge alone:

1 URI  app: no badge element at all
2 URIs app: "+1" badge, aria-label "1 more redirect URI" (singular), title = the one remaining URI
3 URIs app: "+2" badge, aria-label "2 more redirect URIs" (plural), title = the two remaining URIs, one per line

Both singular/plural wording and the tooltip's per-line URI list matched
redirect_uris.slice(1).join("\n") exactly for both multi-URI apps.
Hovering the badge itself didn't render into a screenshot — it's a native
browser title-attribute tooltip (OS/browser-chrome popup), which doesn't
rasterize into an automated capture even on a real hover; the DOM check
above is the reliable verification for this case.

17-18. Public-client (DCR) app in the edit form

On the DCR app's edit page, the redirect-URIs description read exactly:
"This app has no client secret, so http is limited to a loopback address;
https, a custom scheme, and the out-of-band URN are also accepted."

http://app.localhost/callback      -> refused   (unlike the confidential-client case above)
http://127.0.0.1:9999/callback     -> accepted  (loopback still allowed)
https://example.com/callback#frag  -> refused
mailto:someone@example.com         -> refused

Note: the PR description for mailto:/tel:/sms: suggested a
public-client-only code branch is what blocks those schemes. Tried the same
mailto: value against a confidential app as a follow-up, and it was
refused there too, with the identical message — so whatever's actually
blocking mailto: in the UI doesn't appear to be specific to the
public-client branch. Not treating this as a bug (the confidential-client
refusal likely comes from a different, more general check), just noting
that the public-client-only framing may not be distinguishing anything
observable in the UI.

19-21. Keyboard and accessibility

Tabbing from the Name field reached, in order: the Default callback row,
its Remove button, Redirect URI 2, its Remove button, Redirect URI 3, its
Remove button, then "Add redirect URI" — every redirect-URI-specific
control reachable in a sensible order, no trap among them. Enter on "Add
redirect URI" added a row; Shift+Tab to its Remove button, then Space,
removed it correctly.

Two accessibility notes, both pre-existing and unrelated to this PR's
redirect-URI logic:

  • After Space/Enter removes a row, document.activeElement becomes
    <body> immediately (confirmed not transient). In practice the next Tab
    press still lands on a sensible control ("Add redirect URI"), thanks to
    Chromium's default focus-position preservation after removing the
    focused element — not explicit focus management in the form — so it
    isn't a dead end, but a screen reader would announce nothing useful at
    the exact moment of removal.
  • Continuing Tab past "Add redirect URI" toward "Allowed scopes"/"Update
    application" lands on the <em-emoji-picker> custom element used by the
    (out-of-scope, pre-existing) Icon field, and neither Tab, Shift+Tab, nor
    Escape can move focus off it — a genuine two-directional keyboard trap
    that blocks a keyboard-only user from ever reaching "Allowed scopes" or
    "Update"/"Create" from the redirect-URI fields on either form. Confirmed
    it's specific to arriving at the picker via Tab (clicking directly into
    a later field and tabbing from there works normally), so it isn't a
    page-wide issue — just this one field.

Accessible names: removing the first row of a 3-row app renumbered the two
remaining Remove buttons to "Remove redirect URI 1" and "2" (not the stale
"2"/"3" they'd have carried if keyed on a memoized id) — confirming the
name is keyed on the row's current position. The badge's accessible name
was already verified in scenarios 15-16.

22. Icon field regression check

Not part of this PR's redirect-URI change, but spot-checked since it's easy
to verify here. Set an icon on an app via the API, confirmed it appeared in
the edit form's Icon field, cleared the field, and saved:

PUT with icon set              -> icon: "/emojis/1f389.png"
(cleared in the UI, submitted)
GET after save                 -> icon: ""

Icon cleared, not left at its old value — the update request sends the
empty icon rather than omitting it. Applications table also showed the
fallback letter-avatar afterward, not the emoji.

23-24. Cleanup

Deleted every app created during this run (the create-form submission, the
badge-count scratch app, and the seeded DCR app) through each edit page's
"Delete" button and its confirm dialog. Applications table returned to "No
OAuth2 applications configured," matching the pre-run empty state.

Note: the delete-confirmation field showed each app's name pre-filled
on dialog open (resembling browser autofill), but the "Delete" button
stayed disabled against that pre-filled text — clicking it would have done
nothing. Retyping the name via keyboard was required each time before
"Delete" enabled. Not a redirect-URI issue, but worth flagging: a user
could reasonably assume the pre-filled text already satisfies the
confirmation and be confused when Delete stays disabled.

DCR flag restored to its pre-run value (false), confirmed via the API
before and after the restore.

Editing an app's callback added a new accepted URI without removing the
old one, and the admin API only showed the callback (PLAT-619, SEC-870).

- Backfill every row so the callback is the first redirect URI. The
  migration handles empty, missing, and out-of-order lists and is safe
  to rerun. The callback column is kept, marked deprecated.
- Read redirect URIs from the list only. A callback that is not in the
  list is no longer accepted.
- Write both columns together from one shared function. A callback-only
  update now replaces the previous primary and keeps the rest.
- Validate every entry the same way as the callback.
- Cap the list at 32 entries of 2048 bytes each, including at
  registration.

No existing request or response changes shape.
… app update

- Admin updates re-checked the whole stored list against the new caps.
- Apps registered before the caps with over 32 URIs, or a URI over 2048 bytes, could not be edited at all.
- Only URIs the request adds are checked now. The count cap applies only when the list grows.
… redirect URIs

- An old replica writes only callback_url on an admin update.
- New replicas read redirect_uris first, so that edit is not seen until the app is saved again.
- Drain old replicas before upgrading to avoid it.
…de window

- redirect_uris is now the source of truth, with the primary first.
- During a rolling upgrade, a callback edit on an old replica is not seen by new replicas until the app is saved again.
- An app may register at most 32 redirect URIs of at most 2048 bytes each. Older apps beyond that keep working.
- Covers all four documented input shapes, plus dedup and callback ordering.
- The doc comment notes that the list-with-callback and neither shapes get their caller when the admin API gains redirect_uris in the next PR.
…he callback field

- A failure on the request callback_url now says "callback URL ..." with no list index.
- List entries keep the indexed wording for registration callers.
…lidation

- The shape check now rejects fragments, so admin and registration store the same rules.
- Rename ValidateOAuth2CallbackURL to ValidateOAuth2RedirectURIShape and the local validator to validateAppRedirectURIFields.
- The column comment says "first entry of redirect_uris" instead of a 1-based index.
- RegisteredRedirectURIs documents that it is never empty.
- Test that registration stores a deduplicated list. Use plain numbered test URIs.
- ValidateRedirectURI now rejects hostless http(s) and opaque URIs for every client type.
- Move the shared rules into a helper so both paths use one copy.
- Test that ValidateRedirectURI rejects everything the shape check rejects.
…upgrade

- The doc bullet and migration comment said the edit was "not visible".
- They now say it is silently discarded and the app keeps accepting the previous redirect URIs until saved again.
- Drop the forward reference to the next PR from the resolveRedirectURIs doc.
- Let the public client rejection message stand on its own instead of repeating "public client".
- Remove the oauth2_callback_url struct tag. It ran the shape check first and failed with a generic tag message.
- The handler already runs the same check and names the reason against callback_url.
- Test that a callback with a fragment reports that reason.
…pdate itself

- The RFC 7592 update path validated the full resent list with no stored context, so a legacy over-cap client could not save any change.
- It now skips redirect URIs the client already has and applies the count cap only when the list grew, matching the admin path.
- Create still enforces the caps on every entry.
- Remove the duplicated ValidateRedirectURIScheme doc comment.
- Legacy clients may store duplicates, and the stored baseline is deduplicated.
- Resending the list as returned no longer reads as growth.
- Stored redirect URIs are checked again on every update, with no exception for apps that predate the caps.
- An app over the limits must be deleted and created or registered again.
- Remove the duplicated ValidateRedirectURIScheme doc comment again.
…hority

- Registration accepted the bare scheme:value form before this change.
- Add test cases for the three private-use forms.
- Rename ValidateOAuth2RedirectURIShape to ValidateRedirectURIShape to match its siblings.
- Scheme errors no longer start with "redirect URI", since every caller adds its own subject.
…callback_url

- Add redirect_uris to the app response and the create/update requests.
- callback_url still works but is deprecated; it equals the first entry.
- Fix a bug where an empty redirect_uris list was silently ignored instead
  of rejected.
- Update fixtures, tests, and docs for the new field.
CI failed because redirect_uris is required on the generated type
but missing from the entities.ts mocks.
BobbyHo added a commit that referenced this pull request Sep 22, 2026
…callback_url (#29502)

- Add `redirect_uris` to admin OAuth2 app responses and create/update requests.
- Deprecate `callback_url` while preserving compatibility; it maps to the first redirect URI.
- Reject empty `redirect_uris` lists instead of silently ignoring them.
- Update fixtures, tests, and docs.

Part of PLAT-619. Builds on #29440; admin UI support follows in #29603.
Base automatically changed from plat-619-2-api to main September 22, 2026 19:12
Main squashed the API PR this branch was stacked on and then fixed the
stored invalid callback case in the old single-field form. Take main's
Go tests, migration numbering, and docs wording, keep the redirect URI
list form, and port the stored invalid value fix to the list: mark the
field touched on load when the stored list fails validation so its
errors show right away.

Also correct the style guide coverage table so the style-claims hook
passes; main is currently red on that check.
…eck redirect URI uniqueness once over the list

The duplicate check ran on each row and had to find its own index by
matching a regex against the Yup path, with the sibling list typed as
unknown. Move it onto the array, where the value is typed as a list of
strings, and report each duplicate row through createError. Every row
that repeats an earlier one is now flagged in the same pass instead of
one per validation.
@coderagents

coderagents Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/admin/integrations/oauth2-provider.md (open) - Under "Method 1: Web UI" the form field list still names Callback URL, but this PR replaces that field with a Redirect URIs section: the first row is labeled "Default callback", more rows are added with "Add redirect URI", at least one is required and up to 32 are allowed. Update that field entry to describe the list instead of the single field.

Automated review via Coder Agents

…ss the OAuth2 client type to the app form

The form read the client type from the optional app prop, so a missing
app silently meant confidential rules. Take the type as its own required
prop instead. The edit page passes the loaded app's type and the create
page passes confidential, since public clients only come from dynamic
client registration.
…): move RedirectURIsField under components

Keep page views and forms at the top of the page folder and the building
blocks they use under components, matching other page folders.
…it an unchanged redirect URI list from app updates

The form sent the loaded list on every update, so a rename made after
another admin removed a URI restored that URI. Send redirect_uris only
when the ordered list differs from the loaded one, as the form already
does for scope. Creates and list edits still send the full list.

A create must always carry the list while an update may leave it out,
so the app and onSubmit props are now a union of a create variant that
submits the POST request type and an edit variant that submits the PUT
request type.
…im a redirect URI before validating it

The old callback field trimmed before its tests ran, but the per-row
schema did not, so a pasted URL with a leading space failed the anchored
http(s) check and disabled save even though submit trims it. Restore the
trim and cover padded https and loopback http values, since the existing
padded cases only used custom schemes.
…ed the scopes query in the new edit stories

The form always loads the scope catalog, so without the fixture these
two stories made a real request that the Storybook test server refused
and showed an unrelated scopes error next to the redirect URI state they
are meant to capture.
…over the redirect URI byte limit at its boundary

The byte-limit table only exercised the app name. Add a table for the
redirect URI: a multibyte URI of exactly the limit submits unchanged and
one byte over does not, while both stay below the limit by string
length, so the test fails if the check ever counts characters.
… of index

The admin endpoint reported a bad entry as "at index N" counting from
zero, while the web UI labels rows from one, so an admin had to
translate the number. Count from one and cover a fragment in a
confidential app's second entry, which passes the form's check and only
fails on the server.

@jakehwll jakehwll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

one nit on how props are destructured, otherwise frontend LGTM 🥳

…): destructure form props in the parameter list

OAuth2AppForm took a single props argument and pulled fields out of it
on the next line. It did this because the props type is a discriminated
union on app and onSubmit, and destructuring them separately would stop
a check on app from narrowing onSubmit.

Destructure the plain props in the parameter list and collect app and
onSubmit into a rest object. TypeScript keeps the union through object
rest, so the submit handler still narrows the same way.
@BobbyHo
BobbyHo merged commit 528dd3c into main Sep 23, 2026
31 checks passed
@BobbyHo
BobbyHo deleted the plat-619-3-form branch September 23, 2026 15:39
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants