Skip to content

fix: show selected owner's external auth when creating a workspace#26653

Open
aslilac wants to merge 1 commit into
mainfrom
lilac/external-auth-owner
Open

fix: show selected owner's external auth when creating a workspace#26653
aslilac wants to merge 1 commit into
mainfrom
lilac/external-auth-owner

Conversation

@aslilac

@aslilac aslilac commented Jun 24, 2026

Copy link
Copy Markdown
Member

When an admin creates a workspace for another user, the External Authentication section now reflects the selected owner's auth state instead of the admin's.

Previously the form always reported the requesting admin's external auth, so an admin connected to a provider saw "Authenticated" and could submit even when the target owner had never connected it.

Behavior

  • The form reports the selected owner's external auth state.
  • When creating for another user, the "Login with ..." button is replaced with a read-only status, since logging in would authenticate the admin rather than the owner. A short note explains the owner must connect it themselves.
  • Required-but-unconnected providers still block submission, as before.
Implementation details & decisions

Root cause. External auth was keyed by template version only. The backend endpoint looked up links using the requester's ID, and the form never passed the selected owner.

Backend. GET /templateversions/{ver}/external-auth accepts an optional user_id. When it differs from the requester, the requester is authorized for create workspace as that owner (mirroring workspace creation). The owner's link status is then read under an elevated read-only context, so admins who can create for others but lack personal read access (e.g. org admins) still work. The build path already resolves external auth per owner, so this only corrects the form.

Decisions / tradeoffs.

  • Another user's token is never refreshed from this read-only status check (refresh mutates). Status is based on link existence; the build refreshes and skips invalid tokens at provision time.
  • authenticate_url is omitted for non-self responses so the UI cannot offer a login action that would authenticate the wrong account.
  • Submission stays blocked when a required provider is unconnected for the selected owner (least-surprising, avoids builds that would be missing required auth).

Tests. Backend: an org admin (create-for-owner, no personal read) sees the owner's state; a plain member is forbidden. Frontend: Storybook play tests cover the read-only status and the "another user" form state.


Generated by Coder Agents on behalf of @aslilac.

When an admin created a workspace for another user, the external
authentication section reflected the admin's own auth state instead of
the selected owner's, because the endpoint and form keyed external auth
by template version only.

The external-auth endpoint now accepts an optional user_id. When it
differs from the requester, it authorizes create-workspace-for-owner,
reads the owner's link status under an elevated read-only context, and
omits the authenticate URL. The create form threads the selected owner
through the query and shows a read-only status for other users instead
of a login button that would authenticate the admin.
@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/reference/api/templates.md

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.

1 participant