Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,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 @@ -1212,7 +1212,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 @@ -1226,6 +1226,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