feat: add dingtalk union_id (#1110)

This commit is contained in:
tom2nonames
2022-09-08 14:44:06 +08:00
committed by GitHub
parent e158b58ffa
commit 6035b98653
3 changed files with 12 additions and 0 deletions

View File

@ -121,6 +121,7 @@ func (idp *DingTalkIdProvider) GetToken(code string) (*oauth2.Token, error) {
type DingTalkUserResponse struct { type DingTalkUserResponse struct {
Nick string `json:"nick"` Nick string `json:"nick"`
OpenId string `json:"openId"` OpenId string `json:"openId"`
UnionId string `json:"unionId"`
AvatarUrl string `json:"avatarUrl"` AvatarUrl string `json:"avatarUrl"`
Email string `json:"email"` Email string `json:"email"`
Errmsg string `json:"message"` Errmsg string `json:"message"`
@ -162,6 +163,7 @@ func (idp *DingTalkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
Id: dtUserInfo.OpenId, Id: dtUserInfo.OpenId,
Username: dtUserInfo.Nick, Username: dtUserInfo.Nick,
DisplayName: dtUserInfo.Nick, DisplayName: dtUserInfo.Nick,
UnionId: dtUserInfo.UnionId,
Email: dtUserInfo.Email, Email: dtUserInfo.Email,
AvatarUrl: dtUserInfo.AvatarUrl, AvatarUrl: dtUserInfo.AvatarUrl,
} }

View File

@ -25,6 +25,7 @@ type UserInfo struct {
Id string Id string
Username string Username string
DisplayName string DisplayName string
UnionId string
Email string Email string
AvatarUrl string AvatarUrl string
} }

View File

@ -137,6 +137,15 @@ func SetUserOAuthProperties(organization *Organization, user *User, providerType
user.Email = userInfo.Email user.Email = userInfo.Email
} }
} }
if userInfo.UnionId != "" {
propertyName := fmt.Sprintf("oauth_%s_unionId", providerType)
setUserProperty(user, propertyName, userInfo.UnionId)
if providerType == "DingTalk" && user.DingTalk == "" {
user.DingTalk = userInfo.UnionId
}
}
if userInfo.AvatarUrl != "" { if userInfo.AvatarUrl != "" {
propertyName := fmt.Sprintf("oauth_%s_avatarUrl", providerType) propertyName := fmt.Sprintf("oauth_%s_avatarUrl", providerType)
setUserProperty(user, propertyName, userInfo.AvatarUrl) setUserProperty(user, propertyName, userInfo.AvatarUrl)