Compare commits
3 commits
forgejo
...
feat/sso-p
Author | SHA1 | Date | |
---|---|---|---|
f87a6d8b5a | |||
f59a2ae7e1 | |||
d5628bc98d |
3 changed files with 11 additions and 1 deletions
|
@ -22,11 +22,13 @@ const (
|
|||
OAuth2UsernameNickname OAuth2UsernameType = "nickname"
|
||||
// OAuth2UsernameEmail username of oauth2 email field will be used as gitea name
|
||||
OAuth2UsernameEmail OAuth2UsernameType = "email"
|
||||
// @OAuth2UsernamePreferredUsername oauth2 preferred_username field will be used as gitea name
|
||||
OAuth2UsernamePreferredUsername OAuth2UsernameType = "username"
|
||||
)
|
||||
|
||||
func (username OAuth2UsernameType) isValid() bool {
|
||||
switch username {
|
||||
case OAuth2UsernameUserid, OAuth2UsernameNickname, OAuth2UsernameEmail:
|
||||
case OAuth2UsernameUserid, OAuth2UsernameNickname, OAuth2UsernameEmail, OAuth2UsernamePreferredUsername:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -387,6 +387,12 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
|
|||
|
||||
func getUserName(gothUser *goth.User) (string, error) {
|
||||
switch setting.OAuth2Client.Username {
|
||||
case setting.OAuth2UsernamePreferredUsername:
|
||||
username := gothUser.RawData["preferred_username"].(string)
|
||||
if strings.Contains(username, "@") {
|
||||
return user_model.NormalizeUserName(strings.Split(username, "@")[0])
|
||||
}
|
||||
return user_model.NormalizeUserName(username)
|
||||
case setting.OAuth2UsernameEmail:
|
||||
return user_model.NormalizeUserName(strings.Split(gothUser.Email, "@")[0])
|
||||
case setting.OAuth2UsernameNickname:
|
||||
|
|
|
@ -959,6 +959,8 @@ func SignInOAuthCallback(ctx *context.Context) {
|
|||
}
|
||||
if setting.OAuth2Client.Username == setting.OAuth2UsernameNickname && gothUser.NickName == "" {
|
||||
missingFields = append(missingFields, "nickname")
|
||||
} else if setting.OAuth2Client.Username == setting.OAuth2UsernamePreferredUsername && gothUser.RawData["preferred_username"].(string) == "" {
|
||||
missingFields = append(missingFields, "preferred_nickname")
|
||||
}
|
||||
if len(missingFields) > 0 {
|
||||
// we don't have enough information to create an account automatically,
|
||||
|
|
Loading…
Reference in a new issue