Skip to content

fix(auth): derive SSO display name from email local-part#23

Merged
UsamaSadiq merged 3 commits into
foss-sandboxfrom
fix/sso-display-name-from-email-local-part
Jun 2, 2026
Merged

fix(auth): derive SSO display name from email local-part#23
UsamaSadiq merged 3 commits into
foss-sandboxfrom
fix/sso-display-name-from-email-local-part

Conversation

@hunzlahmalik

Copy link
Copy Markdown

Summary

  • Drop the x-auth-request-user header read in the ForwardAuth middleware — oauth2-proxy was putting the Cognito sub UUID into that header, so newly-provisioned SSO users landed with a UUID (e.g. 892ae5ac-0021-…) as their User.name.
  • Use the email local-part as the display name. The middleware already fell back to this value when the header was absent; we're promoting that fallback to the only source.
  • Consolidate the two SSO-provision tests in authentication.test.ts into one — after the fix, the x-auth-request-user-absent branch is the only branch. Also update the AUTH_TYPE JSDoc in env.ts to drop the stale mention of X-Auth-Request-User.

Existing users with UUID name values are not auto-corrected — the middleware does not re-sync the field on subsequent logins. A backfill is out of scope here.

Test plan

  • yarn test server/middlewares/authentication.test.ts passes
  • yarn tsc --noEmit passes
  • Devstack end-to-end: a fresh Cognito user whose cognito:username is the bare sub UUID lands at https://foss-wiki.local.moneta.dev with User.name = email local-part, not the UUID
  • SELECT email, name FROM users ORDER BY "createdAt" DESC LIMIT 5; reflects the new behavior

🤖 Generated with Claude Code

oauth2-proxy was putting the Cognito sub UUID into x-auth-request-user
instead of a human-readable username, so newly-provisioned SSO users
landed with a UUID as their User.name. Drop the header read in the
ForwardAuth middleware and use the email local-part instead — the
same value both apps already fell back to when the header was absent;
we're promoting that fallback to the only source.

Existing users with UUID names are not auto-corrected: the middleware
does not re-sync the name field on subsequent logins.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hunzlahmalik hunzlahmalik changed the base branch from foss-main to foss-sandbox June 1, 2026 12:15
@UsamaSadiq UsamaSadiq requested a review from Copilot June 2, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts ForwardAuth/SSO user provisioning so a newly created SSO user’s User.name is always derived from the email local-part, avoiding cases where oauth2-proxy forwards a UUID into the previous X-Auth-Request-User header.

Changes:

  • Remove X-Auth-Request-User as an input to SSO display-name derivation; use email local-part only.
  • Consolidate SSO provisioning tests to reflect the single name-derivation path.
  • Update AUTH_TYPE environment variable JSDoc to remove the stale header mention and document the new behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
server/middlewares/authentication.ts Stop reading x-auth-request-user and set provisioned User.name from the email local-part.
server/middlewares/authentication.test.ts Remove the now-obsolete test branch that depended on x-auth-request-user.
server/env.ts Update AUTH_TYPE documentation to match current SSO header usage and naming behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/middlewares/authentication.ts Outdated
hunzlahmalik and others added 2 commits June 2, 2026 15:29
A malformed X-Auth-Request-Email with no local part (e.g. "@example.com")
normalises to "@<DEFAULT_EMAIL_DOMAIN>", yielding an empty localPart. Since
User.name enforces a min length of 1, provisioning failed with an opaque
validation error. Source localPart from parseEmail and reject empty local
parts up front with an AuthenticationError for a deterministic failure mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@UsamaSadiq UsamaSadiq merged commit c9972c9 into foss-sandbox Jun 2, 2026
1 check failed
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.

3 participants