Skip to content

Commit

Permalink
Merge pull request #1520 from dexidp/gitlab-groups-scope
Browse files Browse the repository at this point in the history
gitlab: add groups scope by default when filtering is requested
  • Loading branch information
srenatus authored Sep 4, 2019
2 parents 179cce3 + ef08ad8 commit 3b7292a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions connector/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type gitlabConnector struct {

func (c *gitlabConnector) oauth2Config(scopes connector.Scopes) *oauth2.Config {
gitlabScopes := []string{scopeUser}
if scopes.Groups {
if c.groupsRequired(scopes.Groups) {
gitlabScopes = []string{scopeUser, scopeOpenID}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *gitlabConnector) HandleCallback(s connector.Scopes, r *http.Request) (i
identity.UserID = user.Username
}

if s.Groups {
if c.groupsRequired(s.Groups) {
groups, err := c.getGroups(ctx, client, s.Groups, user.Username)
if err != nil {
return identity, fmt.Errorf("gitlab: get groups: %v", err)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (c *gitlabConnector) Refresh(ctx context.Context, s connector.Scopes, ident
ident.Username = username
ident.Email = user.Email

if s.Groups {
if c.groupsRequired(s.Groups) {
groups, err := c.getGroups(ctx, client, s.Groups, user.Username)
if err != nil {
return ident, fmt.Errorf("gitlab: get groups: %v", err)
Expand All @@ -209,6 +209,10 @@ func (c *gitlabConnector) Refresh(ctx context.Context, s connector.Scopes, ident
return ident, nil
}

func (c *gitlabConnector) groupsRequired(groupScope bool) bool {
return len(c.groups) > 0 || groupScope
}

// user queries the GitLab API for profile information using the provided client. The HTTP
// client is expected to be constructed by the golang.org/x/oauth2 package, which inserts
// a bearer token as part of the request.
Expand Down

0 comments on commit 3b7292a

Please sign in to comment.