-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add OAuth2 userinfo endpoint #14938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OAuth2 userinfo endpoint #14938
Changes from all commits
adc441f
e7c7fc3
d64c427
ac982a8
221408f
91619e7
4d87466
f36725e
ebe2d37
7a2ca76
4209065
dc29ed2
1489f99
36e6818
0a3aea7
3ba7c55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package user | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/context" | ||
) | ||
|
||
// userInfoResponse represents a successful userinfo response | ||
type userInfoResponse struct { | ||
Sub string `json:"sub"` | ||
Name string `json:"name"` | ||
Username string `json:"preferred_username"` | ||
Email string `json:"email"` | ||
Picture string `json:"picture"` | ||
} | ||
|
||
// InfoOAuth responds with OAuth formatted userinfo | ||
func InfoOAuth(ctx *context.Context) { | ||
user := ctx.User | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this PR! There is a chance that user may be nil, could you do a check that user != nil to ensure a nil referenceerror doesn't happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may be more complicated. Not the nil check, but the correctness of the userinfo endpoint itself. AuthorizeOAuth reads the bearer token, and I suspect this code may need to do it too. I am relying on Particularly, the Can you confirm that the required signed in context takes the Authorization header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userinfo endpoint should work exclusively with token provided as this is endpoint that is called as s2s request so there won't be user cookies etc for user session |
||
response := &userInfoResponse{ | ||
Sub: fmt.Sprint(user.ID), | ||
Name: user.FullName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes fullname is empty, this could have a fallback if fullname is empty then use Name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically per spec, this isn't required, but if it is empty they recommend not including it. So I won't block on this. |
||
Username: user.Name, | ||
Email: user.Email, | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Picture: user.AvatarLink(), | ||
} | ||
ctx.JSON(http.StatusOK, response) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.