Merge pull request #1627 from jfrabaute/master
google: Retrieve all the groups for a user
This commit is contained in:
commit
aca67b0839
1 changed files with 17 additions and 8 deletions
|
@ -240,17 +240,26 @@ 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()
|
||||
var userGroups []string
|
||||
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)
|
||||
}
|
||||
|
||||
var userGroups []string
|
||||
for _, group := range groupsList.Groups {
|
||||
// TODO (joelspeed): Make desried group key configurable
|
||||
userGroups = append(userGroups, group.Email)
|
||||
}
|
||||
|
||||
if groupsList.NextPageToken == "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return userGroups, nil
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue