Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
20274136
Unverified
Commit
20274136
authored
2 years ago
by
Márk Sági-Kazár
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2696 from dexidp/backport-2694
Backport #2694 to v2.35.x
parents
e4bceef9
261adee2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connector/google/google.go
+13
-9
13 additions, 9 deletions
connector/google/google.go
connector/google/google_test.go
+5
-18
5 additions, 18 deletions
connector/google/google_test.go
with
18 additions
and
27 deletions
connector/google/google.go
+
13
−
9
View file @
20274136
...
...
@@ -71,13 +71,10 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
scopes
=
append
(
scopes
,
"profile"
,
"email"
)
}
var
srv
*
admin
.
Service
if
len
(
c
.
Groups
)
>
0
{
srv
,
err
=
createDirectoryService
(
c
.
ServiceAccountFilePath
,
c
.
AdminEmail
,
logger
)
if
err
!=
nil
{
cancel
()
return
nil
,
fmt
.
Errorf
(
"could not create directory service: %v"
,
err
)
}
srv
,
err
:=
createDirectoryService
(
c
.
ServiceAccountFilePath
,
c
.
AdminEmail
,
logger
)
if
err
!=
nil
{
cancel
()
return
nil
,
fmt
.
Errorf
(
"could not create directory service: %v"
,
err
)
}
clientID
:=
c
.
ClientID
...
...
@@ -286,7 +283,9 @@ func (c *googleConnector) getGroups(email string, fetchTransitiveGroupMembership
// the google admin api. If no serviceAccountFilePath is defined, the application default credential
// is used.
func
createDirectoryService
(
serviceAccountFilePath
,
email
string
,
logger
log
.
Logger
)
(
*
admin
.
Service
,
error
)
{
if
email
==
""
{
// We know impersonation is required when using a service account credential
// TODO: or is it?
if
email
==
""
&&
serviceAccountFilePath
!=
""
{
return
nil
,
fmt
.
Errorf
(
"directory service requires adminEmail"
)
}
...
...
@@ -311,7 +310,12 @@ func createDirectoryService(serviceAccountFilePath, email string, logger log.Log
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to parse credentials to config: %v"
,
err
)
}
config
.
Subject
=
email
// Only attempt impersonation when there is a user configured
if
email
!=
""
{
config
.
Subject
=
email
}
return
admin
.
NewService
(
ctx
,
option
.
WithHTTPClient
(
config
.
Client
(
ctx
)))
}
...
...
This diff is collapsed.
Click to expand it.
connector/google/google_test.go
+
5
−
18
View file @
20274136
...
...
@@ -72,22 +72,13 @@ func TestOpen(t *testing.T) {
assert
.
Nil
(
t
,
err
)
for
name
,
reference
:=
range
map
[
string
]
testCase
{
"not_requesting_groups"
:
{
config
:
&
Config
{
ClientID
:
"testClient"
,
ClientSecret
:
"testSecret"
,
RedirectURI
:
ts
.
URL
+
"/callback"
,
Scopes
:
[]
string
{
"openid"
},
},
expectedErr
:
""
,
},
"missing_admin_email"
:
{
config
:
&
Config
{
ClientID
:
"testClient"
,
ClientSecret
:
"testSecret"
,
RedirectURI
:
ts
.
URL
+
"/callback"
,
Scopes
:
[]
string
{
"openid"
,
"groups"
},
Groups
:
[]
string
{
"someGroup"
}
,
ClientID
:
"testClient"
,
ClientSecret
:
"testSecret"
,
RedirectURI
:
ts
.
URL
+
"/callback"
,
Scopes
:
[]
string
{
"openid"
,
"groups"
},
ServiceAccountFilePath
:
serviceAccountFilePath
,
},
expectedErr
:
"requires adminEmail"
,
},
...
...
@@ -99,7 +90,6 @@ func TestOpen(t *testing.T) {
Scopes
:
[]
string
{
"openid"
,
"groups"
},
AdminEmail
:
"foo@bar.com"
,
ServiceAccountFilePath
:
"not_found.json"
,
Groups
:
[]
string
{
"someGroup"
},
},
expectedErr
:
"error reading credentials"
,
},
...
...
@@ -111,7 +101,6 @@ func TestOpen(t *testing.T) {
Scopes
:
[]
string
{
"openid"
,
"groups"
},
AdminEmail
:
"foo@bar.com"
,
ServiceAccountFilePath
:
serviceAccountFilePath
,
Groups
:
[]
string
{
"someGroup"
},
},
expectedErr
:
""
,
},
...
...
@@ -122,7 +111,6 @@ func TestOpen(t *testing.T) {
RedirectURI
:
ts
.
URL
+
"/callback"
,
Scopes
:
[]
string
{
"openid"
,
"groups"
},
AdminEmail
:
"foo@bar.com"
,
Groups
:
[]
string
{
"someGroup"
},
},
adc
:
serviceAccountFilePath
,
expectedErr
:
""
,
...
...
@@ -135,7 +123,6 @@ func TestOpen(t *testing.T) {
Scopes
:
[]
string
{
"openid"
,
"groups"
},
AdminEmail
:
"foo@bar.com"
,
ServiceAccountFilePath
:
serviceAccountFilePath
,
Groups
:
[]
string
{
"someGroup"
},
},
adc
:
"/dev/null"
,
expectedErr
:
""
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment