feat: OAuth provider lark supports getting phone number (#3047)

This commit is contained in:
Zhen Xiao 2024-07-11 08:56:28 +08:00 committed by GitHub
parent 13d73732ce
commit cc979c310e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,7 @@ import (
"strings"
"time"
"github.com/nyaruka/phonenumbers"
"golang.org/x/oauth2"
)
@ -199,12 +200,25 @@ func (idp *LarkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
return nil, err
}
var phoneNumber string
var countryCode string
if len(larkUserInfo.Data.Mobile) != 0 {
phoneNumberParsed, err := phonenumbers.Parse(larkUserInfo.Data.Mobile, "")
if err != nil {
return nil, err
}
countryCode = phonenumbers.GetRegionCodeForNumber(phoneNumberParsed)
phoneNumber = fmt.Sprintf("%d", phoneNumberParsed.GetNationalNumber())
}
userInfo := UserInfo{
Id: larkUserInfo.Data.OpenId,
DisplayName: larkUserInfo.Data.EnName,
Username: larkUserInfo.Data.Name,
Email: larkUserInfo.Data.Email,
AvatarUrl: larkUserInfo.Data.AvatarUrl,
Phone: phoneNumber,
CountryCode: countryCode,
}
return &userInfo, nil
}