Skip to content

fix(server): use the gateway's admin view for SSO sessions - #246

Open
0717lee wants to merge 1 commit into
contextforge-org:mainfrom
0717lee:fix/sso-admin-profile
Open

0717lee wants to merge 1 commit into
contextforge-org:mainfrom
0717lee:fix/sso-admin-profile

Conversation

@0717lee

@0717lee 0717lee commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Keycloak sign-in proves identity, but resolveSsoUser() always sets is_admin: false. Users whose realm role is mapped to platform_admin by the gateway (SSO_KEYCLOAK_ROLE_MAPPINGS) therefore never see the admin-only Settings tabs, even though the gateway itself treats them as admins and /api/admin/* calls through the BFF succeed.

After the ID token is verified and before the BFF session is created, fetch the gateway's own user record with that user's access token:

  • GET ${CONTEXTFORGE_URL}/auth/email/me with upstreamAuthHeader(accessToken), a 3 s timeout, and the client IP headers
  • overlay is_admin, full_name and auth_provider onto the session user; email still comes from the verified ID token

The lookup never fails the login. Network errors, non-2xx responses, non-JSON bodies and malformed bodies log a warning and keep today's is_admin: false fallback -- permissions remain enforced gateway-side, so this only changes which UI is shown. This also covers users on gateway versions without /auth/email/me.

Tests

  • New regression: a Keycloak login whose gateway profile returns is_admin: true, full_name: "Gateway Admin" and auth_provider: "keycloak" produces those values in /auth/session, and the profile request carries Authorization: Bearer <access token>.
  • New fallback regression: a 503 from /auth/email/me still establishes the session with is_admin: false and the ID-token profile.
  • Red/green: the success regression fails when the overlay call is removed.

Local: SSO callback 19/19; full BFF server suite 26 files / 301 tests passed; npm run typecheck, eslint and prettier on changed files.

Fixes #245

Keycloak sign-in only proved identity; resolveSsoUser always set is_admin=false, so SSO users mapped to platform_admin in the gateway never saw the admin-only Settings tabs. After the token check, call the gateway's /auth/email/me with the user's access token and overlay is_admin, full_name and auth_provider on the session user. A failed lookup keeps today's non-admin fallback because permissions remain enforced gateway-side.

Adds regressions for the gateway-mapped admin profile and the failed-lookup fallback.

Fixes contextforge-org#245

Signed-off-by: Li Fengmin <2080291162@qq.com>
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.

SSO (Keycloak) users never see admin-only UI (Settings → Users/Teams), even when the gateway treats them as platform_admin

1 participant