diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index bf197bd14d..e329729dcd 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -231,7 +231,7 @@ func newAccessTokenResponse(ctx go_context.Context, grant *auth.OAuth2Grant, ser Nonce: grant.Nonce, } if grant.ScopeContains("profile") { - idToken.Name = user.GetDisplayName() + idToken.Name = user.DisplayName() idToken.PreferredUsername = user.Name idToken.Profile = user.HTMLURL() idToken.Picture = user.AvatarLink(ctx) @@ -305,7 +305,7 @@ func InfoOAuth(ctx *context.Context) { response := &userInfoResponse{ Sub: fmt.Sprint(ctx.Doer.ID), - Name: ctx.Doer.FullName, + Name: ctx.Doer.DisplayName(), Username: ctx.Doer.Name, Email: ctx.Doer.Email, Picture: ctx.Doer.AvatarLink(ctx), diff --git a/routers/web/auth/oauth_test.go b/routers/web/auth/oauth_test.go index 5a4a646577..a5f2dd7713 100644 --- a/routers/web/auth/oauth_test.go +++ b/routers/web/auth/oauth_test.go @@ -10,7 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/services/auth/source/oauth2" "github.com/golang-jwt/jwt/v5" @@ -67,32 +67,14 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) { // Scopes: openid profile email oidcToken = createAndParseToken(t, grants[0]) - assert.Equal(t, user.Name, oidcToken.Name) - assert.Equal(t, user.Name, oidcToken.PreferredUsername) - assert.Equal(t, user.HTMLURL(), oidcToken.Profile) - assert.Equal(t, user.AvatarLink(db.DefaultContext), oidcToken.Picture) - assert.Equal(t, user.Website, oidcToken.Website) - assert.Equal(t, user.UpdatedUnix, oidcToken.UpdatedAt) - assert.Equal(t, user.Email, oidcToken.Email) - assert.Equal(t, user.IsActive, oidcToken.EmailVerified) - - // set DefaultShowFullName to true - oldDefaultShowFullName := setting.UI.DefaultShowFullName - setting.UI.DefaultShowFullName = true - defer func() { - setting.UI.DefaultShowFullName = oldDefaultShowFullName - }() - - // Scopes: openid profile email - oidcToken = createAndParseToken(t, grants[0]) - assert.Equal(t, user.FullName, oidcToken.Name) - assert.Equal(t, user.Name, oidcToken.PreferredUsername) - assert.Equal(t, user.HTMLURL(), oidcToken.Profile) - assert.Equal(t, user.AvatarLink(db.DefaultContext), oidcToken.Picture) - assert.Equal(t, user.Website, oidcToken.Website) - assert.Equal(t, user.UpdatedUnix, oidcToken.UpdatedAt) - assert.Equal(t, user.Email, oidcToken.Email) - assert.Equal(t, user.IsActive, oidcToken.EmailVerified) + assert.Equal(t, "User Five", oidcToken.Name) + assert.Equal(t, "user5", oidcToken.PreferredUsername) + assert.Equal(t, "https://try.gitea.io/user5", oidcToken.Profile) + assert.Equal(t, "https://try.gitea.io/assets/img/avatar_default.png", oidcToken.Picture) + assert.Equal(t, "", oidcToken.Website) + assert.Equal(t, timeutil.TimeStamp(0), oidcToken.UpdatedAt) + assert.Equal(t, "user5@example.com", oidcToken.Email) + assert.True(t, oidcToken.EmailVerified) } func TestEncodeCodeChallenge(t *testing.T) {