Skip to content

Commit

Permalink
add @ to end of username if not present
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby authored and juanfont committed Nov 23, 2024
1 parent d72663a commit dc07779
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hscontrol/types/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"cmp"
"strconv"
"strings"

v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/hscontrol/util"
Expand Down Expand Up @@ -50,8 +51,14 @@ type User struct {
// enabled with OIDC, which means that there is a domain involved which
// should be used throughout headscale, in information returned to the
// user and the Policy engine.
// If the username does not contain an '@' it will be added to the end.
func (u *User) Username() string {
return cmp.Or(u.Email, u.Name, u.ProviderIdentifier, strconv.FormatUint(uint64(u.ID), 10))
username := cmp.Or(u.Email, u.Name, u.ProviderIdentifier, strconv.FormatUint(uint64(u.ID), 10))
if !strings.Contains(username, "@") {
username = username + "@"
}

return username
}

// DisplayNameOrUsername returns the DisplayName if it exists, otherwise
Expand Down

0 comments on commit dc07779

Please sign in to comment.