如何使用朋友和比迪包装资源处理程序?
我已成功让 oAuth 对路由进行身份验证:
(defn auth-handler [request] (friend/authorize #{::user}
{:status 200
:body "a secret"}))
(def routes ["/" {true auth-handler}])
(def app (make-handler routes))
(web/run-dmc (-> app
var
(friend/authenticate
{:allow-anon? true
:workflows [(oauth/workflow
{:client-config client-config
:uri-config uri-config
:credential-fn credential-fn})]})
(wrap-resource "public")
(wrap-defaults site-defaults)
))
这适用于“/”路线,但我想确保如果不先进行身份验证就无法访问某些资源。
这似乎是可能的friend/wrap-authorize
功能:
我最接近的尝试适用于 auth 包装的路由,但与非 /dev/ 路由不匹配:
(def routes ["/" [["dev/" [[true (friend/wrap-authorize (resources {:prefix "dev/"}) #{::user})]]]
[true (resources {:prefix "public/"})]]])
(match-route routes "/dev/index.html")
=>
{:handler #object[cemerick.friend$wrap_authorize$fn__24411
0x2400d0be
"cemerick.friend$wrap_authorize$fn__24411@2400d0be"]}
;correct
(match-route routes "/index.html")
=>
nil
;not correct
我认为路由模式的匹配部分[true (resources {:prefix "public/"})]
是错误的,因为当我将其更改为:key
“index.html”时确实匹配。
如何将非 /dev/* 路由匹配到公共资源?