prevent basic enforced in dev mode

This commit is contained in:
Umputun
2018-02-22 02:45:30 -06:00
parent a423d86d0b
commit a565e40a06
+9 -10
View File
@@ -37,18 +37,17 @@ func (a *Authenticator) Auth(reqAuth bool) func(http.Handler) http.Handler {
f := func(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// dev user - skip regular auth check and populate dev to context
if a.basicDevUser(w, r) {
user := devUser
ctx := r.Context()
ctx = context.WithValue(ctx, rest.ContextKey("user"), user)
r = r.WithContext(ctx)
h.ServeHTTP(w, r)
return
}
session, err := a.SessionStore.Get(r, "remark")
if err != nil && reqAuth { // in full auth lack of session causes Unauthorized
if a.basicDevUser(w, r) { // fail-back to dev user if enabled
user := devUser
ctx := r.Context()
ctx = context.WithValue(ctx, rest.ContextKey("user"), user)
r = r.WithContext(ctx)
h.ServeHTTP(w, r)
return
}
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}