adeel / ring-http-basic-auth

Ring middleware for basic HTTP authentication.
9 stars 5 forks source link

Dynamic user binding throws #2

Open ghost opened 7 years ago

ghost commented 7 years ago

Log

$ lein do clean, figwheel
Figwheel: Cutting some fruit, just a sec ...
Retrieving ring-http-basic-auth/ring-http-basic-auth/0.0.1/ring-http-basic-auth-0.0.1.pom from clojars
Retrieving org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from central
Retrieving clj-base64/clj-base64/0.0.1/clj-base64-0.0.1.pom from clojars
Retrieving org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from central
Retrieving ring-http-basic-auth/ring-http-basic-auth/0.0.1/ring-http-basic-auth-0.0.1.jar from clojars
Retrieving clj-base64/clj-base64/0.0.1/clj-base64-0.0.1.jar from clojars
Figwheel: Validating the configuration found in project.clj
Figwheel: Configuration Valid :)
Warning: *user* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *user* or change the name. (ring/middleware/http_basic_auth.clj:5)
Figwheel: Starting server at http://0.0.0.0:3449
Figwheel: Watching build - app
Figwheel: Cleaning build - app
Compiling "target/cljsbuild/public/js/app.js" from ["src/cljs" "src/cljc" "env/dev/cljs"]...
java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: ring.middleware.http-basic-auth/*user*
    at clojure.lang.Var.pushThreadBindings(Var.java:320)
    at clojure.core$push_thread_bindings.invokeStatic(core.clj:1837)
    at clojure.core$push_thread_bindings.invoke(core.clj:1821)
    at ring.middleware.http_basic_auth$wrap_require_auth$fn__29750.invoke(http_basic_auth.clj:41)
    at compojure.core$routing$fn__26594.invoke(core.clj:151)
    at clojure.core$some.invokeStatic(core.clj:2592)
    at clojure.core$some.invoke(core.clj:2583)
    at compojure.core$routing.invokeStatic(core.clj:151)
    at compojure.core$routing.doInvoke(core.clj:148)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invokeStatic(core.clj:648)
    at clojure.core$apply.invoke(core.clj:641)
    at compojure.core$routes$fn__26598.invoke(core.clj:156)
    at clojure.lang.Var.invoke(Var.java:379)
    at ring.middleware.anti_forgery$wrap_anti_forgery$fn__28512.invoke(anti_forgery.clj:91)
    at ring.middleware.flash$wrap_flash$fn__27287.invoke(flash.clj:35)
    at ring.middleware.session$wrap_session$fn__28357.invoke(session.clj:103)
    at ring.middleware.keyword_params$wrap_keyword_params$fn__28393.invoke(keyword_params.clj:35)
    at ring.middleware.nested_params$wrap_nested_params$fn__28445.invoke(nested_params.clj:86)
    at ring.middleware.multipart_params$wrap_multipart_params$fn__28615.invoke(multipart_params.clj:133)
    at ring.middleware.params$wrap_params$fn__28643.invoke(params.clj:64)
    at ring.middleware.cookies$wrap_cookies$fn__28232.invoke(cookies.clj:161)
    at ring.middleware.absolute_redirects$wrap_absolute_redirects$fn__28805.invoke(absolute_redirects.clj:38)
    at ring.middleware.resource$wrap_resource$fn__28683.invoke(resource.clj:28)
    at ring.middleware.content_type$wrap_content_type$fn__28758.invoke(content_type.clj:30)
    at ring.middleware.default_charset$wrap_default_charset$fn__28780.invoke(default_charset.clj:26)
    at ring.middleware.not_modified$wrap_not_modified$fn__28737.invoke(not_modified.clj:52)
    at ring.middleware.x_headers$wrap_xss_protection$fn__27263.invoke(x_headers.clj:71)
    at ring.middleware.x_headers$wrap_frame_options$fn__27251.invoke(x_headers.clj:38)
    at ring.middleware.x_headers$wrap_content_type_options$fn__27257.invoke(x_headers.clj:53)
    at prone.middleware$wrap_exceptions$fn__29063.invoke(middleware.clj:122)
    at ring.middleware.reload$wrap_reload$fn__29597.invoke(reload.clj:38)
    at clojure.lang.Var.invoke(Var.java:379)
    at figwheel_sidecar.components.figwheel_server$possible_endpoint$fn__23252.invoke(figwheel_server.clj:200)
    at figwheel_sidecar.components.figwheel_server$handle_static_resources$fn__23233.invoke(figwheel_server.clj:173)
    at figwheel_sidecar.components.figwheel_server$handle_index$fn__23223.invoke(figwheel_server.clj:160)
    at figwheel_sidecar.components.figwheel_server$handle_figwheel_websocket$fn__23246.invoke(figwheel_server.clj:195)
    at ring.middleware.cors$wrap_cors$fn__22535.invoke(cors.clj:156)
    at figwheel_sidecar.components.figwheel_server$log_output_to_figwheel_server_log$fn__23214.invoke(figwheel_server.clj:141)
    at org.httpkit.server.HttpHandler.run(RingHandler.java:91)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Successfully compiled "target/cljsbuild/public/js/app.js" in 29.883 seconds.
Figwheel: Starting CSS Watcher for paths  ["resources/public/css"]
Figwheel: Starting nREPL server on port: 7002
Launching ClojureScript REPL for build: app
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild [id ...])      ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once [id ...])           ;; builds source one time
          (clean-builds [id ..])          ;; deletes compiled cljs target files
          (print-config [id ...])         ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: Control+C or :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application

handler.clj

(ns rs-handbook.handler
  (:require [compojure.core :refer [GET defroutes]]
            [compojure.route :refer [not-found resources]]
            [hiccup.page :refer [include-js include-css html5]]
            [rs-handbook.middleware :refer [wrap-middleware]]
            [config.core :refer [env]]
            [ring.middleware.http-basic-auth :refer [wrap-require-auth]]))

(def mount-target
  [:div#app
      [:h3 "ClojureScript has not been compiled!"]
      [:p "please run "
       [:b "lein figwheel"]
       " in order to start the compiler"]])

(defn head []
  [:head
   [:meta {:charset "utf-8"}]
   [:meta {:name "viewport"
           :content "width=device-width, initial-scale=1"}]
   (include-css (if (env :dev) "/css/site.css" "/css/site.min.css"))])

(defn authenticate [username password]
  (if (and (= username "username")
           (= password "password"))
    {:username username}))

(defn loading-page []
  (html5
    (head)
    [:body {:class "body-container"}
     mount-target
     (include-js "/js/app.js")]))

(defroutes routes
  (GET "/" [] (loading-page))
  (GET "/about" [] (loading-page))

  (resources "/")
  (not-found "Not Found"))

(defroutes auth-routes
  (wrap-require-auth routes authenticate
                     "Forbidden" {:body "Username and password."}))

(def app (wrap-middleware #'auth-routes))

Project is built with https://github.com/reagent-project/reagent-template.

adeel commented 7 years ago

Thanks for reporting. Can you try declaring the variable *user* as dynamic to see if that fixes the issue? I don't have a proper Clojure setup at the moment, sorry.