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:
Steve0x2a
2021-12-27 18:55:25 +08:00
committed by GitHub
parent 9943e3c316
commit 067ae5448f
2 changed files with 32 additions and 3 deletions

View File

@ -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)
}
}