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
61312e72
Commit
61312e72
authored
5 years ago
by
Cyrille Nofficial
Committed by
Rui Yang
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add parameter configuration to override email claim key
Signed-off-by:
Rui Yang
<
ruiya@vmware.com
>
parent
52c39fb1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Documentation/connectors/oidc.md
+5
-0
5 additions, 0 deletions
Documentation/connectors/oidc.md
connector/oidc/oidc.go
+12
-2
12 additions, 2 deletions
connector/oidc/oidc.go
connector/oidc/oidc_test.go
+17
-0
17 additions, 0 deletions
connector/oidc/oidc_test.go
with
34 additions
and
2 deletions
Documentation/connectors/oidc.md
+
5
−
0
View file @
61312e72
...
...
@@ -56,6 +56,11 @@ connectors:
# - email
# - groups
# Some providers return no standard email claim key (ex: 'mail')
# Override email claim key
# Default is "email"
# emailClaim: email
# Some providers return claims without "email_verified", when they had no usage of emails verification in enrollment process
# or if they are acting as a proxy for another IDP etc AWS Cognito with an upstream SAML IDP
# This can be overridden with the below option
...
...
This diff is collapsed.
Click to expand it.
connector/oidc/oidc.go
+
12
−
2
View file @
61312e72
...
...
@@ -58,6 +58,9 @@ type Config struct {
// Configurable key which contains the preferred username claims
PreferredUsernameKey
string
`json:"preferredUsernameKey"`
// EmailClaim override email claim key. Defaults to "email"
EmailClaim
string
`json:"emailClaim"`
// PromptType will be used fot the prompt parameter (when offline_access, by default prompt=consent)
PromptType
string
`json:"promptType"`
}
...
...
@@ -112,6 +115,11 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
endpoint
.
AuthStyle
=
oauth2
.
AuthStyleInParams
}
emailClaim
:=
"email"
if
len
(
c
.
EmailClaim
)
>
0
{
emailClaim
=
c
.
EmailClaim
}
scopes
:=
[]
string
{
oidc
.
ScopeOpenID
}
if
len
(
c
.
Scopes
)
>
0
{
scopes
=
append
(
scopes
,
c
.
Scopes
...
)
...
...
@@ -147,6 +155,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
userIDKey
:
c
.
UserIDKey
,
userNameKey
:
c
.
UserNameKey
,
preferredUsernameKey
:
c
.
PreferredUsernameKey
,
emailClaim
:
emailClaim
,
promptType
:
c
.
PromptType
,
},
nil
}
...
...
@@ -170,6 +179,7 @@ type oidcConnector struct {
userIDKey
string
userNameKey
string
preferredUsernameKey
string
emailClaim
string
promptType
string
}
...
...
@@ -286,9 +296,9 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
}
}
email
,
found
:=
claims
[
"
email
"
]
.
(
string
)
email
,
found
:=
claims
[
c
.
email
Claim
]
.
(
string
)
if
!
found
&&
hasEmailScope
{
return
identity
,
errors
.
New
(
"missing
\"
email
\"
c
laim
"
)
return
identity
,
fmt
.
Errorf
(
"missing
\"
%s
\"
claim"
,
c
.
emailC
laim
)
}
emailVerified
,
found
:=
claims
[
"email_verified"
]
.
(
bool
)
...
...
This diff is collapsed.
Click to expand it.
connector/oidc/oidc_test.go
+
17
−
0
View file @
61312e72
...
...
@@ -52,6 +52,7 @@ func TestHandleCallback(t *testing.T) {
preferredUsernameKey
string
insecureSkipEmailVerified
bool
scopes
[]
string
emailClaim
string
expectUserID
string
expectUserName
string
expectPreferredUsername
string
...
...
@@ -72,6 +73,21 @@ func TestHandleCallback(t *testing.T) {
"email_verified"
:
true
,
},
},
{
name
:
"customEmailClaim"
,
userIDKey
:
""
,
// not configured
userNameKey
:
""
,
// not configured
emailClaim
:
"mail"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"emailvalue"
,
token
:
map
[
string
]
interface
{}{
"sub"
:
"subvalue"
,
"name"
:
"namevalue"
,
"mail"
:
"emailvalue"
,
"email_verified"
:
true
,
},
},
{
name
:
"email_verified not in claims, configured to be skipped"
,
insecureSkipEmailVerified
:
true
,
...
...
@@ -206,6 +222,7 @@ func TestHandleCallback(t *testing.T) {
UserIDKey
:
tc
.
userIDKey
,
UserNameKey
:
tc
.
userNameKey
,
PreferredUsernameKey
:
tc
.
preferredUsernameKey
,
EmailClaim
:
tc
.
emailClaim
,
InsecureSkipEmailVerified
:
tc
.
insecureSkipEmailVerified
,
BasicAuthUnsupported
:
&
basicAuth
,
}
...
...
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