1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-21 08:31:27 -05:00

Use DisplayName() instead of FullName in Oauth provider (#19991)

Use DisplayName() in Oauth as this provides a fallback if FullName is not set.

Closes #19382
This commit is contained in:
oGi4i 2022-06-17 01:29:54 +03:00 committed by GitHub
parent e3e06d13af
commit 9068c784c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -215,7 +215,7 @@ func newAccessTokenResponse(ctx stdContext.Context, grant *auth.OAuth2Grant, ser
Nonce: grant.Nonce,
}
if grant.ScopeContains("profile") {
idToken.Name = user.FullName
idToken.Name = user.GetDisplayName()
idToken.PreferredUsername = user.Name
idToken.Profile = user.HTMLURL()
idToken.Picture = user.AvatarLink()

View file

@ -11,6 +11,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/services/auth/source/oauth2"
"github.com/golang-jwt/jwt/v4"
@ -64,6 +65,24 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, grants, 1)
// 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(), 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)