Skip to content

Commit

Permalink
Use user.FullName in Oauth2 id_token response
Browse files Browse the repository at this point in the history
This makes `/login/oauth/authorize` behave the same way as the
`/login/oauth/userinfo` endpoint.
  • Loading branch information
baltitenger committed Nov 17, 2024
1 parent c3dedcf commit a457312
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion routers/web/auth/oauth2_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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),
Expand Down
20 changes: 1 addition & 19 deletions routers/web/auth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,7 @@ 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.DisplayName(), 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)
Expand Down
2 changes: 1 addition & 1 deletion services/oauth2_provider/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
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)
Expand Down

0 comments on commit a457312

Please sign in to comment.