Skip to content
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

Discord OAuth broken: OAuth2 Provider discord returned empty or missing fields: [nickname] #24957

Closed
Fogapod opened this issue May 27, 2023 · 4 comments · Fixed by #30622
Closed
Labels

Comments

@Fogapod
Copy link
Contributor

Fogapod commented May 27, 2023

Description

I have only external registration allowed on my instance and discord is one of external OAuth providers.
When trying to log in with discord, i get 500:

[6471f32b] router: completed GET  for 77.92.241.205:53462, 307 Temporary Redirect in 14.4ms @ auth/oauth.go:844(auth.SignInOAuth)
...rs/web/auth/oauth.go:948:SignInOAuthCallback() [E] [6471f32d] OAuth2 Provider discord returned empty or missing fields: [nickname]
...rs/web/auth/oauth.go:953:SignInOAuthCallback() [E] [6471f32d] CreateUser: OAuth2 Provider discord returned empty or missing fields: [nickname]
[6471f32d] router: completed GET  for 77.92.241.205:53462, 500 Internal Server Error in 400.4ms @ auth/oauth.go:883(auth.SignInOAuthCallback)

I tried setting run mode to debug and log level to trace, didnt get anything useful.

Relevant parts of config:

[service]
REGISTER_EMAIL_CONFIRM            = false
ENABLE_NOTIFY_MAIL                = false
DISABLE_REGISTRATION              = true
ALLOW_ONLY_EXTERNAL_REGISTRATION  = true
ENABLE_CAPTCHA                    = false
REQUIRE_SIGNIN_VIEW               = false
AUTO_WATCH_NEW_REPOS              = false

[openid]
ENABLE_OPENID_SIGNIN = true
ENABLE_OPENID_SIGNUP = false

[oauth2_client]
ENABLE_AUTO_REGISTRATION = true

Setting oauth2_client.USERNAME to "userid" partially solves it, user can be registered:

[6471f55c] router: completed GET  for 77.92.241.205:56364, 307 Temporary Redirect in 21.9ms @ auth/oauth.go:844(auth.SignInOAuth)
[6471f55e] router: completed GET  for 77.92.241.205:56364, 303 See Other in 446.0ms @ auth/oauth.go:883(auth.SignInOAuthCallback)
...rs/web/auth/oauth.go:920:SignInOAuthCallback() [E] [6471f55e-2] UserSignIn: could not find a matching session for this request
[6471f55e-2] router: completed GET  for 77.92.241.205:56364, 500 Internal Server Error in 12.2ms @ auth/oauth.go:883(auth.SignInOAuthCallback)
[6471f55f] router: completed GET  for 77.92.241.205:56364, 303 See Other in 55.9ms @ user/avatar.go:48(user.AvatarByEmailHash)
[6471f557-53] router: polling   GET  for 77.92.241.205:56364, elapsed 3931.0ms @ events/events.go:18(events.Events)

I get another 500 page but user is created and seem to work fine after going to main page. userid setting locks user's username to discord id which is undesirable and it also affects other OAuth providers.
Full name field is correctly set to discord account name this way though.

Note that i am creating new user. This email does not exist in gitea so no account linking happens, this is registration

Gitea Version

1.19.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Compiled from source

Database

SQLite

@wetneb
Copy link

wetneb commented Nov 19, 2023

This is likely solved by https://codeberg.org/forgejo/forgejo/pulls/1757

@Tina-otoge
Copy link

I faced this issue, and the only workaround for now seems to NOT use ENABLE_AUTO_REGISTRATION = true, this way, after logging in with an OAuth provider such as Discord which returns an identity not bound to any account yet, the user is facing a form to complete the missing information, in this case the username.

You can still use ALLOW_ONLY_EXTERNAL_REGISTRATION = true with this.

@wetneb
Copy link

wetneb commented Dec 7, 2023

Forgejo v1.21.2-0 has a fix for this: so that registration is still instantaneous for accounts which provide all of the required information (username and email), with a fallback on the link_account form if not.

@wxiaoguang
Copy link
Contributor

-> Improve oauth2 client "preferred username field" logic and the error handling #30622

wxiaoguang added a commit to wxiaoguang/gitea that referenced this issue Apr 23, 2024
wxiaoguang added a commit to wxiaoguang/gitea that referenced this issue Apr 23, 2024
wxiaoguang added a commit to wxiaoguang/gitea that referenced this issue Apr 23, 2024
wxiaoguang added a commit that referenced this issue Apr 25, 2024
…handling (#30622)

Follow #30454
And fix #24957

When using "preferred_username", if no such field,
`extractUserNameFromOAuth2` (old `getUserName`) shouldn't return an
error. All other USERNAME options do not return such error.

And fine tune some logic and error messages, make code more stable and
more friendly to end users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants