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

Adding Custom Header from claims #532

Merged
merged 4 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,17 @@ 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
allupaku marked this conversation as resolved.
Show resolved Hide resolved

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