Skip to content

Commit

Permalink
Merge pull request #1627 from jfrabaute/master
Browse files Browse the repository at this point in the history
google: Retrieve all the groups for a user
  • Loading branch information
Nándor István Krácser authored Jan 20, 2020
2 parents ea43562 + b85d784 commit aca67b0
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions connector/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,24 @@ func (c *googleConnector) createIdentity(ctx context.Context, identity connector
// getGroups creates a connection to the admin directory service and lists
// all groups the user is a member of
func (c *googleConnector) getGroups(email string) ([]string, error) {
groupsList, err := c.adminSrv.Groups.List().UserKey(email).Do()
if err != nil {
return nil, fmt.Errorf("could not list groups: %v", err)
}

var userGroups []string
for _, group := range groupsList.Groups {
// TODO (joelspeed): Make desried group key configurable
userGroups = append(userGroups, group.Email)
var err error
groupsList := &admin.Groups{}
for {
groupsList, err = c.adminSrv.Groups.List().
UserKey(email).PageToken(groupsList.NextPageToken).Do()
if err != nil {
return nil, fmt.Errorf("could not list groups: %v", err)
}

for _, group := range groupsList.Groups {
// TODO (joelspeed): Make desried group key configurable
userGroups = append(userGroups, group.Email)
}

if groupsList.NextPageToken == "" {
break
}
}

return userGroups, nil
Expand Down

0 comments on commit aca67b0

Please sign in to comment.