forked from forgejo/forgejo
[GITEA] oauth2: use link_account page when email/username is missing (#1757)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1757 Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu> Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu> (cherry picked from commit0f6e0f9035
) (cherry picked from commit779168a572
) (cherry picked from commit29a2457321
) (cherry picked from commita1edc2314d
) (cherry picked from commitcd01594610
) (cherry picked from commit74db46b0f5
) (cherry picked from commitfd98f55204
) (cherry picked from commit3099d0e281
) (cherry picked from commit9fbbe61364
) (cherry picked from commit8c00565006
) (cherry picked from commit0977a1ed75
)
This commit is contained in:
parent
4d76bbeda7
commit
6338fe8bef
2 changed files with 39 additions and 8 deletions
|
@ -952,10 +952,16 @@ func SignInOAuthCallback(ctx *context.Context) {
|
|||
return
|
||||
} else if !setting.Service.AllowOnlyInternalRegistration && setting.OAuth2Client.EnableAutoRegistration {
|
||||
// create new user with details from oauth2 provider
|
||||
var missingFields []string
|
||||
if gothUser.UserID == "" {
|
||||
missingFields = append(missingFields, "sub")
|
||||
log.Error("OAuth2 Provider %s returned empty or missing field: UserID", authSource.Name)
|
||||
if authSource.IsOAuth2() && authSource.Cfg.(*oauth2.Source).Provider == "openidConnect" {
|
||||
log.Error("You may need to change the 'OPENID_CONNECT_SCOPES' setting to request all required fields")
|
||||
}
|
||||
err = fmt.Errorf("OAuth2 Provider %s returned empty or missing field: UserID", authSource.Name)
|
||||
ctx.ServerError("CreateUser", err)
|
||||
return
|
||||
}
|
||||
var missingFields []string
|
||||
if gothUser.Email == "" {
|
||||
missingFields = append(missingFields, "email")
|
||||
}
|
||||
|
@ -963,12 +969,10 @@ func SignInOAuthCallback(ctx *context.Context) {
|
|||
missingFields = append(missingFields, "nickname")
|
||||
}
|
||||
if len(missingFields) > 0 {
|
||||
log.Error("OAuth2 Provider %s returned empty or missing fields: %s", authSource.Name, missingFields)
|
||||
if authSource.IsOAuth2() && authSource.Cfg.(*oauth2.Source).Provider == "openidConnect" {
|
||||
log.Error("You may need to change the 'OPENID_CONNECT_SCOPES' setting to request all required fields")
|
||||
}
|
||||
err = fmt.Errorf("OAuth2 Provider %s returned empty or missing fields: %s", authSource.Name, missingFields)
|
||||
ctx.ServerError("CreateUser", err)
|
||||
// we don't have enough information to create an account automatically,
|
||||
// so we prompt the user for the remaining bits
|
||||
log.Trace("OAuth2 Provider %s returned empty or missing fields: %s, prompting the user for them", authSource.Name, missingFields)
|
||||
showLinkingLogin(ctx, gothUser)
|
||||
return
|
||||
}
|
||||
uname, err := getUserName(&gothUser)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue