Skip to content

Commit

Permalink
update fn
Browse files Browse the repository at this point in the history
  • Loading branch information
oanasc committed Jul 4, 2024
1 parent a5670cd commit 00550c8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/server/domain/service/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ func (a *authenticationServiceImpl) GetLoginType(ctx context.Context) (*apisv1.G
}, nil
}

func getSub(claims *model.Claims) string {
sub := strings.ToLower(claims.Sub)
func getUserName(sub string) string {
username := strings.ToLower(sub)
if len(sub) > datastore.PrimaryKeyMaxLength {
return sub[:datastore.PrimaryKeyMaxLength]
}
return sub
return username
}

func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
Expand Down Expand Up @@ -501,7 +501,7 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
}
user := &model.User{
Email: claims.Email,
Name: getSub(claims),
Name: getUserName(claims.Sub),
DexSub: claims.Sub,
Alias: claims.Name,
LastLoginTime: time.Now(),
Expand All @@ -516,7 +516,7 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
if systemInfo != nil {
for _, project := range systemInfo.DexUserDefaultProjects {
_, err := d.projectService.AddProjectUser(ctx, project.Name, apisv1.AddProjectUserRequest{
UserName: getSub(claims),
UserName: getUserName(claims.Sub),
UserRoles: project.Roles,
})
if err != nil {
Expand Down

0 comments on commit 00550c8

Please sign in to comment.