Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7e80ab24
Commit
7e80ab24
authored
Oct 06, 2016
by
mbohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary authorization headers after authorization is successful
parent
07eba4c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
handlers.go
pkg/auth/handlers/handlers.go
+5
-1
handlers_test.go
pkg/auth/handlers/handlers_test.go
+8
-2
No files found.
pkg/auth/handlers/handlers.go
View file @
7e80ab24
...
...
@@ -43,7 +43,8 @@ func init() {
// WithAuthentication creates an http handler that tries to authenticate the given request as a user, and then
// stores any such user found onto the provided context for the request. If authentication fails or returns an error
// the failed handler is used. On success, handler is invoked to serve the request.
// the failed handler is used. On success, "Authorization" header is removed from the request and handler
// is invoked to serve the request.
func
WithAuthentication
(
handler
http
.
Handler
,
mapper
api
.
RequestContextMapper
,
auth
authenticator
.
Request
,
failed
http
.
Handler
)
http
.
Handler
{
if
auth
==
nil
{
glog
.
Warningf
(
"Authentication is disabled"
)
...
...
@@ -60,6 +61,9 @@ func WithAuthentication(handler http.Handler, mapper api.RequestContextMapper, a
return
}
// authorization header is not required anymore in case of a successful authentication.
req
.
Header
.
Del
(
"Authorization"
)
if
ctx
,
ok
:=
mapper
.
Get
(
req
);
ok
{
mapper
.
Update
(
req
,
api
.
WithUser
(
ctx
,
user
))
}
...
...
pkg/auth/handlers/handlers_test.go
View file @
7e80ab24
...
...
@@ -40,18 +40,24 @@ func TestAuthenticateRequest(t *testing.T) {
if
user
==
nil
||
!
ok
{
t
.
Errorf
(
"no user stored in context: %#v"
,
ctx
)
}
if
req
.
Header
.
Get
(
"Authorization"
)
!=
""
{
t
.
Errorf
(
"Authorization header should be removed from request on success: %#v"
,
req
)
}
close
(
success
)
}),
contextMapper
,
authenticator
.
RequestFunc
(
func
(
req
*
http
.
Request
)
(
user
.
Info
,
bool
,
error
)
{
return
&
user
.
DefaultInfo
{
Name
:
"user"
},
true
,
nil
if
req
.
Header
.
Get
(
"Authorization"
)
==
"Something"
{
return
&
user
.
DefaultInfo
{
Name
:
"user"
},
true
,
nil
}
return
nil
,
false
,
errors
.
New
(
"Authorization header is missing."
)
}),
http
.
HandlerFunc
(
func
(
_
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
t
.
Errorf
(
"unexpected call to failed"
)
}),
)
auth
.
ServeHTTP
(
httptest
.
NewRecorder
(),
&
http
.
Request
{})
auth
.
ServeHTTP
(
httptest
.
NewRecorder
(),
&
http
.
Request
{
Header
:
map
[
string
][]
string
{
"Authorization"
:
{
"Something"
}}
})
<-
success
empty
,
err
:=
api
.
IsEmpty
(
contextMapper
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment