mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-06-08 23:56:36 +02:00
Use comma separated multiple values for header (#799)
* Use comma separated value for multiple claims * Fix lint error * Fix more tests * Fix one more test * Always flatten the headers * Ensure we test the real multi-groups * Only update map when necessary * Update CHANGELOG * Move to the right location of change log * Fix blank line
This commit is contained in:
parent
8087de7a03
commit
b541805dc1
@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
## Changes since v6.1.1
|
## Changes since v6.1.1
|
||||||
|
|
||||||
|
- [#799](https://github.com/oauth2-proxy/oauth2-proxy/pull/799) Use comma separated multiple values for header (@lilida)
|
||||||
- [#903](https://github.com/oauth2-proxy/oauth2-proxy/pull/903) Add docs and generated reference for Alpha configuration (@JoelSpeed)
|
- [#903](https://github.com/oauth2-proxy/oauth2-proxy/pull/903) Add docs and generated reference for Alpha configuration (@JoelSpeed)
|
||||||
- [#995](https://github.com/oauth2-proxy/oauth2-proxy/pull/995) Add Security Policy (@JoelSpeed)
|
- [#995](https://github.com/oauth2-proxy/oauth2-proxy/pull/995) Add Security Policy (@JoelSpeed)
|
||||||
- [#964](https://github.com/oauth2-proxy/oauth2-proxy/pull/964) Require `--reverse-proxy` true to trust `X-Forwareded-*` type headers (@NickMeves)
|
- [#964](https://github.com/oauth2-proxy/oauth2-proxy/pull/964) Require `--reverse-proxy` true to trust `X-Forwareded-*` type headers (@NickMeves)
|
||||||
|
@ -612,7 +612,7 @@ func TestPassGroupsHeadersWithGroups(t *testing.T) {
|
|||||||
rw = httptest.NewRecorder()
|
rw = httptest.NewRecorder()
|
||||||
proxy.ServeHTTP(rw, req)
|
proxy.ServeHTTP(rw, req)
|
||||||
|
|
||||||
assert.Equal(t, groups, req.Header["X-Forwarded-Groups"])
|
assert.Equal(t, []string{"a,b"}, req.Header["X-Forwarded-Groups"])
|
||||||
}
|
}
|
||||||
|
|
||||||
type PassAccessTokenTest struct {
|
type PassAccessTokenTest struct {
|
||||||
|
@ -3,6 +3,7 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/justinas/alice"
|
"github.com/justinas/alice"
|
||||||
middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
|
middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
|
||||||
@ -40,6 +41,14 @@ func newStripHeaders(headers []options.Header) alice.Constructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flattenHeaders(headers http.Header) {
|
||||||
|
for name, values := range headers {
|
||||||
|
if len(values) > 1 {
|
||||||
|
headers.Set(name, strings.Join(values, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func stripHeaders(headers []string, next http.Handler) http.Handler {
|
func stripHeaders(headers []string, next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
for _, header := range headers {
|
for _, header := range headers {
|
||||||
@ -67,6 +76,7 @@ func injectRequestHeaders(injector header.Injector, next http.Handler) http.Hand
|
|||||||
// If scope is nil, this will panic.
|
// If scope is nil, this will panic.
|
||||||
// A scope should always be injected before this handler is called.
|
// A scope should always be injected before this handler is called.
|
||||||
injector.Inject(req.Header, scope.Session)
|
injector.Inject(req.Header, scope.Session)
|
||||||
|
flattenHeaders(req.Header)
|
||||||
next.ServeHTTP(rw, req)
|
next.ServeHTTP(rw, req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -98,6 +108,7 @@ func injectResponseHeaders(injector header.Injector, next http.Handler) http.Han
|
|||||||
// If scope is nil, this will panic.
|
// If scope is nil, this will panic.
|
||||||
// A scope should always be injected before this handler is called.
|
// A scope should always be injected before this handler is called.
|
||||||
injector.Inject(rw.Header(), scope.Session)
|
injector.Inject(rw.Header(), scope.Session)
|
||||||
|
flattenHeaders(req.Header)
|
||||||
next.ServeHTTP(rw, req)
|
next.ServeHTTP(rw, req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,11 @@ var _ = Describe("Headers Suite", func() {
|
|||||||
Entry("with no configured headers", headersTableInput{
|
Entry("with no configured headers", headersTableInput{
|
||||||
headers: []options.Header{},
|
headers: []options.Header{},
|
||||||
initialHeaders: http.Header{
|
initialHeaders: http.Header{
|
||||||
"foo": []string{"bar", "baz"},
|
"Foo": []string{"bar", "baz"},
|
||||||
},
|
},
|
||||||
session: &sessionsapi.SessionState{},
|
session: &sessionsapi.SessionState{},
|
||||||
expectedHeaders: http.Header{
|
expectedHeaders: http.Header{
|
||||||
"foo": []string{"bar", "baz"},
|
"Foo": []string{"bar,baz"},
|
||||||
},
|
},
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
}),
|
}),
|
||||||
@ -77,13 +77,13 @@ var _ = Describe("Headers Suite", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
initialHeaders: http.Header{
|
initialHeaders: http.Header{
|
||||||
"foo": []string{"bar", "baz"},
|
"Foo": []string{"bar", "baz"},
|
||||||
},
|
},
|
||||||
session: &sessionsapi.SessionState{
|
session: &sessionsapi.SessionState{
|
||||||
IDToken: "IDToken-1234",
|
IDToken: "IDToken-1234",
|
||||||
},
|
},
|
||||||
expectedHeaders: http.Header{
|
expectedHeaders: http.Header{
|
||||||
"foo": []string{"bar", "baz"},
|
"Foo": []string{"bar,baz"},
|
||||||
"Claim": []string{"IDToken-1234"},
|
"Claim": []string{"IDToken-1234"},
|
||||||
},
|
},
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -133,7 +133,7 @@ var _ = Describe("Headers Suite", func() {
|
|||||||
IDToken: "IDToken-1234",
|
IDToken: "IDToken-1234",
|
||||||
},
|
},
|
||||||
expectedHeaders: http.Header{
|
expectedHeaders: http.Header{
|
||||||
"Claim": []string{"bar", "baz", "IDToken-1234"},
|
"Claim": []string{"bar,baz,IDToken-1234"},
|
||||||
},
|
},
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
}),
|
}),
|
||||||
@ -176,7 +176,7 @@ var _ = Describe("Headers Suite", func() {
|
|||||||
},
|
},
|
||||||
session: nil,
|
session: nil,
|
||||||
expectedHeaders: http.Header{
|
expectedHeaders: http.Header{
|
||||||
"Claim": []string{"bar", "baz"},
|
"Claim": []string{"bar,baz"},
|
||||||
},
|
},
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user