write www-authenticate and delegate to reva

This commit is contained in:
A.Unger
2020-12-01 16:57:36 +01:00
parent d82f485604
commit 348c54f2e7
7 changed files with 67 additions and 23 deletions
+8 -3
View File
@@ -32,15 +32,18 @@ func BasicAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, req *http.Request) {
if h.isPublicLink(req) || !h.isBasicAuth(req) {
// if we want to prevent duplicated Www-Authenticate headers coming from Reva consider using w.Header().Del("Www-Authenticate")
// but this will require the proxy being aware of endpoints which authentication fallback to Reva.
if !h.isPublicLink(req) {
w.Header().Add("Www-Authenticate", fmt.Sprintf("%v realm=\"%s\", charset=\"UTF-8\"", "Basic", req.Host))
}
next.ServeHTTP(w, req)
return
}
account, ok := h.getAccount(req)
if !ok {
// TODO need correct hostname
w.Header().Add("WWW-Authenticate", "Basic realm=\"Access to localhost\", charset=\"UTF-8\"")
w.Header().Add("Www-Authenticate", fmt.Sprintf("%v realm=\"%s\", charset=\"UTF-8\"", "Basic", req.Host))
w.WriteHeader(http.StatusUnauthorized)
return
}
@@ -50,6 +53,8 @@ func BasicAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
Iss: oidcIss,
}
fmt.Printf("\n\nHGAHAHAHA\n\n")
next.ServeHTTP(w, req.WithContext(oidc.NewContext(req.Context(), claims)))
},
)