Skip to content

Commit 1e0a4d6

Browse files
author
zheyuan.xing
committed
expose error message for jmespath.search
Signed-off-by: zheyuan.xing <[email protected]>
1 parent be62b6e commit 1e0a4d6

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

connector/oauth/oauth.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,34 @@ func (c *oauthConnector) HandleCallback(s connector.Scopes, r *http.Request) (id
215215
c.logger.Errorf("OAuth Connector: not found %v claim", c.userIDKey)
216216
return identity, fmt.Errorf("OAuth Connector: not found %v claim", c.userIDKey)
217217
}
218-
219218
identity.UserID = userID
220-
username, _ := jmespath.Search(c.userNameKey, userInfoResult)
219+
220+
username, err := jmespath.Search(c.userNameKey, userInfoResult)
221+
if err != nil {
222+
c.logger.Errorf("OAuth Connector: failed to search %v claim: %v", c.userNameKey, err)
223+
return identity, fmt.Errorf("OAuth Connector: failed to search %v claim: %v", c.userNameKey, err)
224+
}
221225
identity.Username, _ = username.(string)
222-
preferredUsername, _ := jmespath.Search(c.preferredUsernameKey, userInfoResult)
226+
227+
preferredUsername, err := jmespath.Search(c.preferredUsernameKey, userInfoResult)
228+
if err != nil {
229+
c.logger.Errorf("OAuth Connector: failed to search %v claim: %v", c.preferredUsernameKey, err)
230+
return identity, fmt.Errorf("OAuth Connector: failed to search %v claim: %v", c.preferredUsernameKey, err)
231+
}
223232
identity.PreferredUsername, _ = preferredUsername.(string)
224-
email, _ := jmespath.Search(c.emailKey, userInfoResult)
233+
234+
email, err := jmespath.Search(c.emailKey, userInfoResult)
235+
if err != nil {
236+
c.logger.Errorf("OAuth Connector: failed to search %v claim: %v", c.emailKey, err)
237+
return identity, fmt.Errorf("OAuth Connector: failed to search %v claim: %v", c.emailKey, err)
238+
}
225239
identity.Email, _ = email.(string)
226-
emailVerified, _ := jmespath.Search(c.emailVerifiedKey, userInfoResult)
240+
241+
emailVerified, err := jmespath.Search(c.emailVerifiedKey, userInfoResult)
242+
if err != nil {
243+
c.logger.Errorf("OAuth Connector: failed to search %v claim: %v", c.emailVerifiedKey, err)
244+
return identity, fmt.Errorf("OAuth Connector: failed to search %v claim: %v", c.emailVerifiedKey, err)
245+
}
227246
identity.EmailVerified, _ = emailVerified.(bool)
228247

229248
if s.Groups {
@@ -250,7 +269,11 @@ func (c *oauthConnector) HandleCallback(s connector.Scopes, r *http.Request) (id
250269
}
251270

252271
func (c *oauthConnector) addGroups(groups map[string]struct{}, result interface{}) error {
253-
tmpGroupsClaim, _ := jmespath.Search(c.groupsKey, result)
272+
tmpGroupsClaim, err := jmespath.Search(c.groupsKey, result)
273+
if err != nil {
274+
return errors.New(fmt.Sprintf("failed to search %v claim: %v", c.groupsKey, err))
275+
}
276+
254277
groupsClaim, ok := tmpGroupsClaim.([]interface{})
255278
if !ok {
256279
return errors.New("cannot convert to slice")

0 commit comments

Comments
 (0)