[PR #2633] [CLOSED] Fix: Populate user name from email prefix if OIDC username is invalid #2771

Closed
opened 2025-12-29 04:18:55 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/2633
Author: @0xlilim
Created: 5/28/2025
Status: Closed

Base: mainHead: main


📝 Commits (3)

  • 243112b Fix: Populate user name from email prefix if OIDC username is invalid
  • c4062c4 Fix: Improve OIDC username fallback and email parsing
  • daccf72 Fix: Improve OIDC username fallback, email parsing, and code clarity ;)

📊 Changes

1 file changed (+33 additions, -6 deletions)

View changed files

📝 hscontrol/types/users.go (+33 -6)

📄 Description

Fixed: Populate user name from email prefix if OIDC username is invalid.

When a user authenticates via OIDC and the preferred_username claim
(mapped to claims.Username) contains characters disallowed by
util.ValidateUsername (e.g., CJK characters), the User.Name field
would remain empty. This resulted in an empty 'Name' column in the
headscale user list output for such users.

This commit modifies the User.FromClaim method in
hscontrol/types/users.go to address this issue. If claims.Username
is empty or fails validation, the method now attempts to extract the
prefix from claims.Email (the part before '@'). If this extracted
prefix is valid according to util.ValidateUsername, it is used as
the User.Name.

This ensures that a valid username is populated when possible, even if
the OIDC preferred_username is not directly usable, improving the
user experience and data consistency.

  • [x ] have read the CONTRIBUTING.md file
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/2633 **Author:** [@0xlilim](https://github.com/0xlilim) **Created:** 5/28/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (3) - [`243112b`](https://github.com/juanfont/headscale/commit/243112bc6e23f97c28a1d664a2ac0ed4c5c0bd4c) Fix: Populate user name from email prefix if OIDC username is invalid - [`c4062c4`](https://github.com/juanfont/headscale/commit/c4062c425dfb2e1dbf75712057546429e7c86dbe) Fix: Improve OIDC username fallback and email parsing - [`daccf72`](https://github.com/juanfont/headscale/commit/daccf722f91be3f11afe72db3f04bc84f49e0342) Fix: Improve OIDC username fallback, email parsing, and code clarity ;) ### 📊 Changes **1 file changed** (+33 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `hscontrol/types/users.go` (+33 -6) </details> ### 📄 Description **Fixed: Populate user name from email prefix if OIDC username is invalid.** When a user authenticates via OIDC and the `preferred_username` claim (mapped to `claims.Username`) contains characters disallowed by `util.ValidateUsername` (e.g., CJK characters), the `User.Name` field would remain empty. This resulted in an empty 'Name' column in the `headscale user list` output for such users. This commit modifies the `User.FromClaim` method in `hscontrol/types/users.go` to address this issue. If `claims.Username` is empty or fails validation, the method now attempts to extract the prefix from `claims.Email` (the part before '@'). If this extracted prefix is valid according to `util.ValidateUsername`, it is used as the `User.Name`. This ensures that a valid username is populated when possible, even if the OIDC `preferred_username` is not directly usable, improving the user experience and data consistency. - [x ] have read the [CONTRIBUTING.md](./CONTRIBUTING.md) file - [ ] raised a GitHub issue or discussed it on the projects chat beforehand - [ ] added unit tests - [ ] added integration tests - [ ] updated documentation if needed - [ ] updated CHANGELOG.md --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 04:18:55 +01:00
adam closed this issue 2025-12-29 04:18:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2771