forked from kyma-incubator/compass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_middleware.go
29 lines (21 loc) · 992 Bytes
/
context_middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package authentication
import (
"net/http"
"github.com/kyma-incubator/compass/components/connector/pkg/oathkeeper"
)
type authContextMiddleware struct {
}
func NewAuthenticationContextMiddleware() *authContextMiddleware {
return &authContextMiddleware{}
}
func (acm *authContextMiddleware) PropagateAuthentication(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
clientIdFromToken := r.Header.Get(oathkeeper.ClientIdFromTokenHeader)
r = r.WithContext(PutIntoContext(r.Context(), ClientIdFromTokenKey, clientIdFromToken))
clientIdFromCertificate := r.Header.Get(oathkeeper.ClientIdFromCertificateHeader)
r = r.WithContext(PutIntoContext(r.Context(), ClientIdFromCertificateKey, clientIdFromCertificate))
clientCertificateHash := r.Header.Get(oathkeeper.ClientCertificateHashHeader)
r = r.WithContext(PutIntoContext(r.Context(), ClientCertificateHashKey, clientCertificateHash))
handler.ServeHTTP(w, r)
})
}