Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Adding Custom Header from claims (#532)
Browse files Browse the repository at this point in the history
* Adding claim parameter mapping to custom header
* Fixing linting issue
* Fixing Linter reported usage of magic numbers
* Fixing Linter reported usage of magic numbers

Resolves #532
Co-authored-by: Althaf <althaf@spiatech.com>
  • Loading branch information
allupaku authored Jun 18, 2020
1 parent 9de3d16 commit 4c3331a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,18 @@ func (r *oauthProxy) responseHeaderMiddleware(headers map[string]string) func(ht
// identityHeadersMiddleware is responsible for add the authentication headers for the upstream
func (r *oauthProxy) identityHeadersMiddleware(custom []string) func(http.Handler) http.Handler {
customClaims := make(map[string]string)

const minSliceLength int = 1

for _, x := range custom {
customClaims[x] = fmt.Sprintf("X-Auth-%s", toHeader(x))
xslices := strings.Split(x, "|")
x = xslices[0]

if len(xslices) > minSliceLength {
customClaims[x] = toHeader(xslices[1])
} else {
customClaims[x] = fmt.Sprintf("X-Auth-%s", toHeader(x))
}
}

cookieFilter := []string{r.config.CookieAccessName, r.config.CookieRefreshName}
Expand Down
3 changes: 2 additions & 1 deletion middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ func TestCustomHeadersHandler(t *testing.T) {
},
},
{
Match: []string{"given_name", "family_name"},
Match: []string{"given_name", "family_name", "preferred_username|Custom-Header"},
Request: fakeRequest{
URI: fakeAuthAllURL,
HasToken: true,
Expand All @@ -1322,6 +1322,7 @@ func TestCustomHeadersHandler(t *testing.T) {
ExpectedProxyHeaders: map[string]string{
"X-Auth-Given-Name": "Rohith",
"X-Auth-Family-Name": "Jayawardene",
"Custom-Header": "rjayawardene",
},
ExpectedProxy: true,
ExpectedCode: http.StatusOK,
Expand Down

0 comments on commit 4c3331a

Please sign in to comment.