Skip to content

Add OIDC Token Exchange For Org Admin OAuth Access#4711

Merged
shepilov merged 6 commits intomasterfrom
feat/impersonate_oidc_user
Apr 9, 2026
Merged

Add OIDC Token Exchange For Org Admin OAuth Access#4711
shepilov merged 6 commits intomasterfrom
feat/impersonate_oidc_user

Conversation

@shepilov
Copy link
Copy Markdown
Contributor

Context

The B2B admin app needs to create shared drives on an organization's Cozy instance directly from the browser. The admin user is authenticated by an external OIDC provider, but the target organization Cozy expects normal Cozy OAuth credentials.

Simple flow:

  • Admin frontend calls the target org Cozy directly
  • Cozy validates the external id_token
  • Cozy creates a normal OAuth client on the org instance
  • Cozy returns standard OAuth credentials usable by cozy-client

Changes:

  • Added POST /auth/token_exchange on the normal API.
  • Kept /auth/* globally blocked by generic CORS, and added dedicated CORS handling only for /auth/token_exchange.
  • Restricted token-exchange CORS to origins under the target instance OrgDomain.
  • Added CSP connect-src allowances for:
    • api-login-{orgId}.{base-domain}
    • {orgId}.{base-domain}
    • {orgId}.{orgDomain}
  • Implemented token exchange validation:
    • OIDC signature / issuer / audience checks
    • org_id must match the target instance
    • org_role must be owner or admin
  • Returned a standard OAuth response extended with:
    • client_id
    • client_secret
    • registration_access_token
  • Bound exchanged OAuth clients to OIDC sid when present, so they can be revoked by backchannel logout.

@shepilov shepilov requested a review from a team as a code owner March 25, 2026 13:54
@shepilov shepilov changed the title Feat/impersonate OIDC user Add OIDC Token Exchange For Org Admin OAuth Access Mar 25, 2026
@shepilov shepilov force-pushed the feat/impersonate_oidc_user branch from d4ebf07 to 4cda41c Compare March 25, 2026 14:01
@shepilov shepilov force-pushed the feat/impersonate_oidc_user branch from 4cda41c to 4f82c03 Compare March 25, 2026 14:06
Comment thread web/auth/token_exchange.go Outdated
Comment thread web/auth/token_exchange.go
Comment thread web/auth/token_exchange.go
Comment thread web/auth/token_exchange.go
Comment thread web/auth/token_exchange.go
Comment thread web/auth/token_exchange.go Outdated
Comment thread web/auth/token_exchange.go Outdated
@shepilov shepilov merged commit 84a60d7 into master Apr 9, 2026
4 checks passed
@shepilov shepilov deleted the feat/impersonate_oidc_user branch April 9, 2026 12:41
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