mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
fix: idp using goth shows wrong display name (#398)
* fix: adjust the accessToken field Signed-off-by: 0x2a <stevesough@gmail.com> * fix: missing name and owner Signed-off-by: 0x2a <stevesough@gmail.com> * fix: get wrong display name Signed-off-by: 0x2a <stevesough@gmail.com>
This commit is contained in:
23
idp/goth.go
23
idp/goth.go
@ -21,6 +21,7 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/casbin/casdoor/util"
|
||||
"github.com/markbates/goth"
|
||||
"github.com/markbates/goth/providers/amazon"
|
||||
"github.com/markbates/goth/providers/apple"
|
||||
@ -244,11 +245,27 @@ func getUser(gothUser goth.User) *UserInfo {
|
||||
//Some idp return an empty Name
|
||||
//so construct the Name with firstname and lastname or nickname
|
||||
if user.Username == "" {
|
||||
user.Username = fmt.Sprintf("%v%v", gothUser.FirstName, gothUser.LastName)
|
||||
if gothUser.FirstName != "" && gothUser.LastName != "" {
|
||||
user.Username = getName(gothUser.FirstName, gothUser.LastName)
|
||||
} else {
|
||||
user.Username = gothUser.NickName
|
||||
}
|
||||
}
|
||||
if user.Username == "" {
|
||||
user.Username = gothUser.NickName
|
||||
if user.DisplayName == "" {
|
||||
if gothUser.FirstName != "" && gothUser.LastName != "" {
|
||||
user.DisplayName = getName(gothUser.FirstName, gothUser.LastName)
|
||||
} else {
|
||||
user.DisplayName = user.Username
|
||||
}
|
||||
}
|
||||
|
||||
return &user
|
||||
}
|
||||
|
||||
func getName(firstName, lastName string) string {
|
||||
if util.IsChinese(firstName) || util.IsChinese(lastName) {
|
||||
return fmt.Sprintf("%s%s", lastName, firstName)
|
||||
} else {
|
||||
return fmt.Sprintf("%s %s", firstName, lastName)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user