Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keycloak-proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Janne Mareike Koschinski
keycloak-proxy
Commits
0a55c3d7
Commit
0a55c3d7
authored
7 years ago
by
Stephane Tang
Browse files
Options
Downloads
Patches
Plain Diff
allow multiple audiences
Signed-off-by:
Stephane Tang
<
hi@stang.sh
>
parent
a6d55e66
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
doc.go
+1
-1
1 addition, 1 deletion
doc.go
middleware.go
+1
-1
1 addition, 1 deletion
middleware.go
user_context.go
+24
-5
24 additions, 5 deletions
user_context.go
user_context_test.go
+4
-1
4 additions, 1 deletion
user_context_test.go
with
30 additions
and
8 deletions
doc.go
+
1
−
1
View file @
0a55c3d7
...
...
@@ -387,7 +387,7 @@ type userContext struct {
// the id of the user
id
string
// the audience for the token
audience
string
audience
s
[]
string
// whether the context is from a session cookie or authorization header
bearerToken
bool
// the claims associated to the token
...
...
This diff is collapsed.
Click to expand it.
middleware.go
+
1
−
1
View file @
0a55c3d7
...
...
@@ -373,7 +373,7 @@ func (r *oauthProxy) identityHeadersMiddleware(custom []string) func(http.Handle
scope
:=
req
.
Context
()
.
Value
(
contextScopeName
)
.
(
*
RequestScope
)
if
scope
.
Identity
!=
nil
{
user
:=
scope
.
Identity
req
.
Header
.
Set
(
"X-Auth-Audience"
,
user
.
audience
)
req
.
Header
.
Set
(
"X-Auth-Audience"
,
strings
.
Join
(
user
.
audience
s
,
","
)
)
req
.
Header
.
Set
(
"X-Auth-Email"
,
user
.
email
)
req
.
Header
.
Set
(
"X-Auth-ExpiresIn"
,
user
.
expiresAt
.
String
())
req
.
Header
.
Set
(
"X-Auth-Groups"
,
strings
.
Join
(
user
.
groups
,
","
))
...
...
This diff is collapsed.
Click to expand it.
user_context.go
+
24
−
5
View file @
0a55c3d7
...
...
@@ -40,9 +40,17 @@ func extractIdentity(token jose.JWT) (*userContext, error) {
if
err
!=
nil
||
!
found
{
preferredName
=
identity
.
Email
}
audience
,
found
,
err
:=
claims
.
StringClaim
(
claimAudience
)
if
err
!=
nil
||
!
found
{
var
audiences
[]
string
aud
,
found
,
err
:=
claims
.
StringClaim
(
claimAudience
)
if
err
==
nil
&&
found
{
audiences
=
append
(
audiences
,
aud
)
}
else
{
if
aud
,
found
,
err
:=
claims
.
StringsClaim
(
claimAudience
);
err
!=
nil
||
!
found
{
return
nil
,
ErrNoTokenAudience
}
else
{
audiences
=
aud
}
}
// @step: extract the realm roles
...
...
@@ -74,7 +82,7 @@ func extractIdentity(token jose.JWT) (*userContext, error) {
}
return
&
userContext
{
audience
:
audience
,
audience
s
:
audience
s
,
claims
:
claims
,
email
:
identity
.
Email
,
expiresAt
:
identity
.
ExpiresAt
,
...
...
@@ -87,9 +95,20 @@ func extractIdentity(token jose.JWT) (*userContext, error) {
},
nil
}
// backported from https://github.com/gambol99/go-oidc/blob/master/oidc/verification.go#L28-L37
// I'll raise another PR to make it public in the go-oidc package so we can just use `oidc.ContainsString()`
func
containsString
(
needle
string
,
haystack
[]
string
)
bool
{
for
_
,
v
:=
range
haystack
{
if
v
==
needle
{
return
true
}
}
return
false
}
// isAudience checks the audience
func
(
r
*
userContext
)
isAudience
(
aud
string
)
bool
{
return
r
.
audience
==
aud
return
containsString
(
aud
,
r
.
audience
s
)
}
// getRoles returns a list of roles
...
...
This diff is collapsed.
Click to expand it.
user_context_test.go
+
4
−
1
View file @
0a55c3d7
...
...
@@ -24,7 +24,7 @@ import (
func
TestIsAudience
(
t
*
testing
.
T
)
{
user
:=
&
userContext
{
audience
:
"test"
,
audience
s
:
[]
string
{
"test"
,
"test2"
}
,
}
if
!
user
.
isAudience
(
"test"
)
{
t
.
Error
(
"return should not have been false"
)
...
...
@@ -32,6 +32,9 @@ func TestIsAudience(t *testing.T) {
if
user
.
isAudience
(
"test1"
)
{
t
.
Error
(
"return should not have been true"
)
}
if
!
user
.
isAudience
(
"test2"
)
{
t
.
Error
(
"return should not have been false"
)
}
}
func
TestGetUserRoles
(
t
*
testing
.
T
)
{
...
...
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