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
2b6bb199
Commit
2b6bb199
authored
3 years ago
by
Happy2C0de
Browse files
Options
Downloads
Patches
Plain Diff
Revert ClaimMapping struct
Signed-off-by:
Happy2C0de
<
46957159+Happy2C0de@users.noreply.github.com
>
parent
14a0aecc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connector/oidc/oidc.go
+20
-19
20 additions, 19 deletions
connector/oidc/oidc.go
connector/oidc/oidc_test.go
+24
-32
24 additions, 32 deletions
connector/oidc/oidc_test.go
with
44 additions
and
51 deletions
connector/oidc/oidc.go
+
20
−
19
View file @
2b6bb199
...
...
@@ -61,19 +61,16 @@ type Config struct {
// This setting allows you to override the default behavior of Dex and enforce the mappings defined in `claimMapping`.
OverrideClaimMapping
bool
`json:"overrideClaimMapping"`
// defaults to false
ClaimMapping
ClaimMapping
`json:"claimMapping"`
}
type
ClaimMapping
struct
{
// Configurable key which contains the preferred username claims
PreferredUsernameKey
string
`json:"preferred_username"`
// defaults to "preferred_username"
ClaimMapping
struct
{
// Configurable key which contains the preferred username claims
PreferredUsernameKey
string
`json:"preferred_username"`
// defaults to "preferred_username"
// Configurable key which contains the email claims
EmailKey
string
`json:"email"`
// defaults to "email"
// Configurable key which contains the email claims
EmailKey
string
`json:"email"`
// defaults to "email"
// Configurable key which contains the groups claims
GroupsKey
string
`json:"groups"`
// defaults to "groups"
// Configurable key which contains the groups claims
GroupsKey
string
`json:"groups"`
// defaults to "groups"
}
`json:"claimMapping"`
}
// Domains that don't support basic auth. golang.org/x/oauth2 has an internal
...
...
@@ -162,7 +159,9 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
userIDKey
:
c
.
UserIDKey
,
userNameKey
:
c
.
UserNameKey
,
overrideClaimMapping
:
c
.
OverrideClaimMapping
,
claimMapping
:
c
.
ClaimMapping
,
preferredUsernameKey
:
c
.
ClaimMapping
.
PreferredUsernameKey
,
emailKey
:
c
.
ClaimMapping
.
EmailKey
,
groupsKey
:
c
.
ClaimMapping
.
GroupsKey
,
},
nil
}
...
...
@@ -186,7 +185,9 @@ type oidcConnector struct {
userIDKey
string
userNameKey
string
overrideClaimMapping
bool
claimMapping
ClaimMapping
preferredUsernameKey
string
emailKey
string
groupsKey
string
}
func
(
c
*
oidcConnector
)
Close
()
error
{
...
...
@@ -296,8 +297,8 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
prefUsername
:=
"preferred_username"
preferredUsername
,
found
:=
claims
[
prefUsername
]
.
(
string
)
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
claimMapping
.
P
referredUsernameKey
!=
""
{
prefUsername
=
c
.
claimMapping
.
P
referredUsernameKey
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
p
referredUsernameKey
!=
""
{
prefUsername
=
c
.
p
referredUsernameKey
preferredUsername
,
found
=
claims
[
prefUsername
]
.
(
string
)
if
!
found
{
return
identity
,
fmt
.
Errorf
(
"missing
\"
%s
\"
claim"
,
prefUsername
)
...
...
@@ -315,8 +316,8 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
var
email
string
emailKey
:=
"email"
email
,
found
=
claims
[
emailKey
]
.
(
string
)
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
claimMapping
.
E
mailKey
!=
""
{
emailKey
=
c
.
claimMapping
.
E
mailKey
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
e
mailKey
!=
""
{
emailKey
=
c
.
e
mailKey
email
,
found
=
claims
[
emailKey
]
.
(
string
)
if
!
found
{
return
identity
,
fmt
.
Errorf
(
"missing
\"
%s
\"
claim"
,
emailKey
)
...
...
@@ -340,8 +341,8 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
if
c
.
insecureEnableGroups
{
groupsKey
:=
"groups"
vs
,
found
:=
claims
[
groupsKey
]
.
([]
interface
{})
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
claimMapping
.
G
roupsKey
!=
""
{
groupsKey
=
c
.
claimMapping
.
G
roupsKey
if
(
!
found
||
c
.
overrideClaimMapping
)
&&
c
.
g
roupsKey
!=
""
{
groupsKey
=
c
.
g
roupsKey
vs
,
found
=
claims
[
groupsKey
]
.
([]
interface
{})
}
...
...
This diff is collapsed.
Click to expand it.
connector/oidc/oidc_test.go
+
24
−
32
View file @
2b6bb199
...
...
@@ -50,7 +50,9 @@ func TestHandleCallback(t *testing.T) {
userIDKey
string
userNameKey
string
overrideClaimMapping
bool
claimMapping
ClaimMapping
preferredUsernameKey
string
emailKey
string
groupsKey
string
insecureSkipEmailVerified
bool
scopes
[]
string
expectUserID
string
...
...
@@ -77,12 +79,10 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name
:
"customEmailClaim"
,
userIDKey
:
""
,
// not configured
userNameKey
:
""
,
// not configured
claimMapping
:
ClaimMapping
{
EmailKey
:
"mail"
,
},
name
:
"customEmailClaim"
,
userIDKey
:
""
,
// not configured
userNameKey
:
""
,
// not configured
emailKey
:
"mail"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"emailvalue"
,
...
...
@@ -98,16 +98,14 @@ func TestHandleCallback(t *testing.T) {
userIDKey
:
""
,
// not configured
userNameKey
:
""
,
// not configured
overrideClaimMapping
:
true
,
claimMapping
:
ClaimMapping
{
EmailKey
:
"custommail"
,
},
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"customemailvalue"
,
emailKey
:
"custommail"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"customemailvalue"
,
token
:
map
[
string
]
interface
{}{
"sub"
:
"subvalue"
,
"name"
:
"namevalue"
,
"mail"
:
"emailvalue"
,
"
e
mail"
:
"emailvalue"
,
"custommail"
:
"customemailvalue"
,
"email_verified"
:
true
,
},
...
...
@@ -151,10 +149,8 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name
:
"withPreferredUsernameKey"
,
claimMapping
:
ClaimMapping
{
PreferredUsernameKey
:
"username_key"
,
},
name
:
"withPreferredUsernameKey"
,
preferredUsernameKey
:
"username_key"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectPreferredUsername
:
"username_value"
,
...
...
@@ -222,10 +218,8 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name
:
"customGroupsKey"
,
claimMapping
:
ClaimMapping
{
GroupsKey
:
"cognito:groups"
,
},
name
:
"customGroupsKey"
,
groupsKey
:
"cognito:groups"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"emailvalue"
,
...
...
@@ -241,10 +235,8 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name
:
"customGroupsKeyButGroupsProvided"
,
claimMapping
:
ClaimMapping
{
GroupsKey
:
"cognito:groups"
,
},
name
:
"customGroupsKeyButGroupsProvided"
,
groupsKey
:
"cognito:groups"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"emailvalue"
,
...
...
@@ -261,11 +253,9 @@ func TestHandleCallback(t *testing.T) {
},
},
{
name
:
"customGroupsKeyButGroupsProvidedButOverride"
,
overrideClaimMapping
:
true
,
claimMapping
:
ClaimMapping
{
GroupsKey
:
"cognito:groups"
,
},
name
:
"customGroupsKeyButGroupsProvidedButOverride"
,
overrideClaimMapping
:
true
,
groupsKey
:
"cognito:groups"
,
expectUserID
:
"subvalue"
,
expectUserName
:
"namevalue"
,
expectedEmailField
:
"emailvalue"
,
...
...
@@ -312,7 +302,9 @@ func TestHandleCallback(t *testing.T) {
BasicAuthUnsupported
:
&
basicAuth
,
OverrideClaimMapping
:
tc
.
overrideClaimMapping
,
}
config
.
ClaimMapping
=
tc
.
claimMapping
config
.
ClaimMapping
.
PreferredUsernameKey
=
tc
.
preferredUsernameKey
config
.
ClaimMapping
.
EmailKey
=
tc
.
emailKey
config
.
ClaimMapping
.
GroupsKey
=
tc
.
groupsKey
conn
,
err
:=
newConnector
(
config
)
if
err
!=
nil
{
...
...
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