Skip to content

Commit

Permalink
feat: add dingtalk union_id (casdoor#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2nonames authored Sep 8, 2022
1 parent e158b58 commit 6035b98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions idp/dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (idp *DingTalkIdProvider) GetToken(code string) (*oauth2.Token, error) {
type DingTalkUserResponse struct {
Nick string `json:"nick"`
OpenId string `json:"openId"`
UnionId string `json:"unionId"`
AvatarUrl string `json:"avatarUrl"`
Email string `json:"email"`
Errmsg string `json:"message"`
Expand Down Expand Up @@ -162,6 +163,7 @@ func (idp *DingTalkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
Id: dtUserInfo.OpenId,
Username: dtUserInfo.Nick,
DisplayName: dtUserInfo.Nick,
UnionId: dtUserInfo.UnionId,
Email: dtUserInfo.Email,
AvatarUrl: dtUserInfo.AvatarUrl,
}
Expand Down
1 change: 1 addition & 0 deletions idp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type UserInfo struct {
Id string
Username string
DisplayName string
UnionId string
Email string
AvatarUrl string
}
Expand Down
9 changes: 9 additions & 0 deletions object/user_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ func SetUserOAuthProperties(organization *Organization, user *User, providerType
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 != "" {
propertyName := fmt.Sprintf("oauth_%s_avatarUrl", providerType)
setUserProperty(user, propertyName, userInfo.AvatarUrl)
Expand Down

0 comments on commit 6035b98

Please sign in to comment.