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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
keycloak-proxy
Commits
cdfb2a93
Commit
cdfb2a93
authored
Feb 16, 2019
by
Philippe Gagnon
Committed by
Bruno Oliveira da Silva
Mar 11, 2019
Browse files
Options
Downloads
Patches
Plain Diff
Add base URI to OAuth routes and set cookies path to Base URI
parent
2d9c8fdc
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
cookies.go
+5
-1
5 additions, 1 deletion
cookies.go
cookies_test.go
+39
-0
39 additions, 0 deletions
cookies_test.go
handlers.go
+0
-4
0 additions, 4 deletions
handlers.go
middleware_test.go
+38
-0
38 additions, 0 deletions
middleware_test.go
server.go
+1
-1
1 addition, 1 deletion
server.go
with
83 additions
and
6 deletions
cookies.go
+
5
−
1
View file @
cdfb2a93
...
@@ -32,11 +32,15 @@ func (r *oauthProxy) dropCookie(w http.ResponseWriter, host, name, value string,
...
@@ -32,11 +32,15 @@ func (r *oauthProxy) dropCookie(w http.ResponseWriter, host, name, value string,
if
r
.
config
.
CookieDomain
!=
""
{
if
r
.
config
.
CookieDomain
!=
""
{
domain
=
r
.
config
.
CookieDomain
domain
=
r
.
config
.
CookieDomain
}
}
path
:=
r
.
config
.
BaseURI
if
path
==
""
{
path
=
"/"
}
cookie
:=
&
http
.
Cookie
{
cookie
:=
&
http
.
Cookie
{
Domain
:
domain
,
Domain
:
domain
,
HttpOnly
:
r
.
config
.
HTTPOnlyCookie
,
HttpOnly
:
r
.
config
.
HTTPOnlyCookie
,
Name
:
name
,
Name
:
name
,
Path
:
"/"
,
Path
:
path
,
Secure
:
r
.
config
.
SecureCookie
,
Secure
:
r
.
config
.
SecureCookie
,
Value
:
value
,
Value
:
value
,
}
}
...
...
This diff is collapsed.
Click to expand it.
cookies_test.go
+
39
−
0
View file @
cdfb2a93
...
@@ -40,6 +40,45 @@ func TestCookieDomainHostHeader(t *testing.T) {
...
@@ -40,6 +40,45 @@ func TestCookieDomainHostHeader(t *testing.T) {
assert
.
Equal
(
t
,
cookie
.
Domain
,
"127.0.0.1"
)
assert
.
Equal
(
t
,
cookie
.
Domain
,
"127.0.0.1"
)
}
}
func
TestCookieBasePath
(
t
*
testing
.
T
)
{
cfg
:=
newFakeKeycloakConfig
()
cfg
.
BaseURI
=
"/base-uri"
_
,
_
,
svc
:=
newTestProxyService
(
cfg
)
resp
,
err
:=
makeTestCodeFlowLogin
(
svc
+
"/admin"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
resp
)
var
cookie
*
http
.
Cookie
for
_
,
c
:=
range
resp
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
cookie
=
c
}
}
assert
.
NotNil
(
t
,
cookie
)
assert
.
Equal
(
t
,
"/base-uri"
,
cookie
.
Path
)
}
func
TestCookieWithoutBasePath
(
t
*
testing
.
T
)
{
cfg
:=
newFakeKeycloakConfig
()
_
,
_
,
svc
:=
newTestProxyService
(
cfg
)
resp
,
err
:=
makeTestCodeFlowLogin
(
svc
+
"/admin"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
resp
)
var
cookie
*
http
.
Cookie
for
_
,
c
:=
range
resp
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
cookie
=
c
}
}
assert
.
NotNil
(
t
,
cookie
)
assert
.
Equal
(
t
,
"/"
,
cookie
.
Path
)
}
func
TestCookieDomain
(
t
*
testing
.
T
)
{
func
TestCookieDomain
(
t
*
testing
.
T
)
{
p
,
_
,
svc
:=
newTestProxyService
(
nil
)
p
,
_
,
svc
:=
newTestProxyService
(
nil
)
p
.
config
.
CookieDomain
=
"domain.com"
p
.
config
.
CookieDomain
=
"domain.com"
...
...
This diff is collapsed.
Click to expand it.
handlers.go
+
0
−
4
View file @
cdfb2a93
...
@@ -210,10 +210,6 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
...
@@ -210,10 +210,6 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
redirectURI
=
string
(
decoded
)
redirectURI
=
string
(
decoded
)
}
}
}
}
if
r
.
config
.
BaseURI
!=
""
{
// assuming state starts with slash
redirectURI
=
r
.
config
.
BaseURI
+
redirectURI
}
r
.
redirectToURL
(
redirectURI
,
w
,
req
,
http
.
StatusTemporaryRedirect
)
r
.
redirectToURL
(
redirectURI
,
w
,
req
,
http
.
StatusTemporaryRedirect
)
}
}
...
...
This diff is collapsed.
Click to expand it.
middleware_test.go
+
38
−
0
View file @
cdfb2a93
...
@@ -354,6 +354,44 @@ func TestOauthRequests(t *testing.T) {
...
@@ -354,6 +354,44 @@ func TestOauthRequests(t *testing.T) {
newFakeProxy
(
cfg
)
.
RunTests
(
t
,
requests
)
newFakeProxy
(
cfg
)
.
RunTests
(
t
,
requests
)
}
}
func
TestOauthRequestsWithBaseURI
(
t
*
testing
.
T
)
{
cfg
:=
newFakeKeycloakConfig
()
cfg
.
BaseURI
=
"/base-uri"
requests
:=
[]
fakeRequest
{
{
URI
:
"/base-uri/oauth/authorize"
,
Redirects
:
true
,
ExpectedCode
:
http
.
StatusTemporaryRedirect
,
},
{
URI
:
"/base-uri/oauth/callback"
,
Redirects
:
true
,
ExpectedCode
:
http
.
StatusBadRequest
,
},
{
URI
:
"/base-uri/oauth/health"
,
Redirects
:
true
,
ExpectedCode
:
http
.
StatusOK
,
},
{
URI
:
"/oauth/authorize"
,
ExpectedProxy
:
true
,
ExpectedCode
:
http
.
StatusOK
,
},
{
URI
:
"/oauth/callback"
,
ExpectedProxy
:
true
,
ExpectedCode
:
http
.
StatusOK
,
},
{
URI
:
"/oauth/health"
,
ExpectedProxy
:
true
,
ExpectedCode
:
http
.
StatusOK
,
},
}
newFakeProxy
(
cfg
)
.
RunTests
(
t
,
requests
)
}
func
TestMethodExclusions
(
t
*
testing
.
T
)
{
func
TestMethodExclusions
(
t
*
testing
.
T
)
{
cfg
:=
newFakeKeycloakConfig
()
cfg
:=
newFakeKeycloakConfig
()
cfg
.
Resources
=
[]
*
Resource
{
cfg
.
Resources
=
[]
*
Resource
{
...
...
This diff is collapsed.
Click to expand it.
server.go
+
1
−
1
View file @
cdfb2a93
...
@@ -197,7 +197,7 @@ func (r *oauthProxy) createReverseProxy() error {
...
@@ -197,7 +197,7 @@ func (r *oauthProxy) createReverseProxy() error {
}
}
// step: add the routing for oauth
// step: add the routing for oauth
engine
.
With
(
proxyDenyMiddleware
)
.
Route
(
r
.
config
.
OAuthURI
,
func
(
e
chi
.
Router
)
{
engine
.
With
(
proxyDenyMiddleware
)
.
Route
(
r
.
config
.
BaseURI
+
r
.
config
.
OAuthURI
,
func
(
e
chi
.
Router
)
{
e
.
MethodNotAllowed
(
methodNotAllowHandlder
)
e
.
MethodNotAllowed
(
methodNotAllowHandlder
)
e
.
HandleFunc
(
authorizationURL
,
r
.
oauthAuthorizationHandler
)
e
.
HandleFunc
(
authorizationURL
,
r
.
oauthAuthorizationHandler
)
e
.
Get
(
callbackURL
,
r
.
oauthCallbackHandler
)
e
.
Get
(
callbackURL
,
r
.
oauthCallbackHandler
)
...
...
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