Skip to content

Commit

Permalink
Instead of trying to guess names, ignore them.
Browse files Browse the repository at this point in the history
  • Loading branch information
ainmosni committed Mar 24, 2023
1 parent 177cd0b commit 10f4af1
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions services/invitations/pkg/backends/keycloak/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/tls"
"fmt"
"strings"

"github.com/Nerzal/gocloak/v13"
"github.com/google/uuid"
Expand Down Expand Up @@ -74,17 +73,14 @@ func (b Backend) CreateUser(ctx context.Context, invitation *invitations.Invitat
}
u := uuid.New()

firstName, lastName := splitDisplayName(invitation.InvitedUserDisplayName)
b.logger.Info().
Str(idAttr, u.String()).
Str("email", invitation.InvitedUserEmailAddress).
Msg("Creating new user")
user := gocloak.User{
FirstName: &firstName,
LastName: &lastName,
Email: &invitation.InvitedUserEmailAddress,
Enabled: gocloak.BoolP(true),
Username: &invitation.InvitedUserEmailAddress,
Email: &invitation.InvitedUserEmailAddress,
Enabled: gocloak.BoolP(true),
Username: &invitation.InvitedUserEmailAddress,
Attributes: &map[string][]string{
idAttr: {u.String()},
userTypeAttr: {userTypeVal},
Expand Down Expand Up @@ -142,14 +138,3 @@ func (b Backend) getToken(ctx context.Context) (*gocloak.JWT, error) {

return token, nil
}

// Quick and dirty way to split the last name off from the first name(s), imperfect, because
// every culture has a different conception of names.
func splitDisplayName(displayName string) (string, string) {
parts := strings.Split(displayName, " ")
if len(parts) <= 1 {
return parts[0], ""
}

return strings.Join(parts[:len(parts)-1], " "), parts[len(parts)-1]
}

0 comments on commit 10f4af1

Please sign in to comment.