i seem to be missing something wrt auth(enticate|orize)> if my :access-control
map contains a :authenticate (fn [ctx] ...)
i get a doesn't conform to resource model schema
error. the docs explicitly say to use the :authenticate fn as opposed to the verify multimethod: https://juxt.pro/yada/manual/index.html#sidebar-function-or-defmethod . am i missing something additional configuration?
:access-control {:scheme :app/cognito
:authenticate (fn [ctx]
(println "we're here")
[:a :b])
:verify (fn [[a b]]
(println "verify" a b)
{:user a
:roles #{:user}})
:authorization {:methods {:get :user}}
}
here’s an example of the failing configI can help with this but afk right now. I'll get back to you.
Take a look at yada.security ns in the code and you'll see what is going on. You need to use a map
@lwhorton Could you paste me your yada resource verbatim? I'd like to figure out what's going wrong.
sure, i’ve gone through quite a few iterations trying to get things to stop complaining, but here’s the cfg that’s failing:
["login"
(y/handler
(y/resource {:id :login
:produces "text/plain"
:access-control {:realms
{"default"
{
:authentication-schemes [{:scheme ":app/cognito"
:authenticate (fn [ctx]
(println "we're here")
[:cred1 :cred2])
}]
:authorization {:methods {:get :user}}
}}}
:methods
{:get {:parameters {:query {:code String}}
:response (fn [ctx]
(let [resp (oauth-2 (get-in ctx [:parameters :query :code]))]
(condp = (:status resp)
200 {:status 302
:cookies {"session" {:value "auth-cookie"}}
:headers {"location" (bidi/path-for routes :index)}}
{:status 401})))}}}))]
it’s likely i’m just doing something wrong either here or elsewhere that’s causing a fuss. i’m only exploring yada (and others) for potential future use as a web framework so i don’t have a ton of time unfortunately
how's it failing - it seems a valid yada resource
the scheme is a bit odd, but should still pass
thanks for the error report though
took me a while to get back to the state-- here’s the stacktrace:
{:type clojure.lang.Compiler$CompilerException
:message "Syntax error compiling at (core.clj:79:8)."
:data #:clojure.error{:phase :compile-syntax-check, :line 79, :column 8, :source "core.clj"}
:at [clojure.lang.Compiler$InvokeExpr eval "Compiler.java" 3707]}
{:type clojure.lang.ExceptionInfo
:message "Cannot turn resource-model into resource, because it doesn't conform to a resource-model schema"
:data {:resource-model {:id :login, :produces "text/plain", :access-control {:realms {"default" {:authentication-schemes [{:scheme ":app/cognito", :authenticate #object[gerbil.web.core$fn__42156 0x746b849 "gerbil.web.core$fn__42156@746b849"]}], :authorization {:methods {:get :user}}}}}, :methods {:get {:parameters {:query {:code java.lang.String}}, :response #object[gerbil.web.core$fn__42158 0x4da94d8b "gerbil.web.core$fn__42158@4da94d8b"]}}}, :error {:access-control {:realms {"default" {:authentication-schemes [{(not (namespace :authenticate)) invalid-key}]}}}}}
if i change the key :authenticate
to :foo/authenticate
the resource validation does not complain
i'm getting the same error in 1.2.16
i also think yada 1.2.16 is not backwards compatible
i'll log an issue for that
bingo https://github.com/juxt/yada/blob/master/src/yada/security.clj#L89-L105
Great.
I'm rewriting auth currently to be async and to make things simpler with respect to realms. However, there shouldn't be any compatibility breakages as I'll ensure existing resource models work as is.
Things are a little awkward right now but please be assured I'm working on it. I've had lots of quality hammock time over the winter break.
that’s good to hear. ive only been fooling around with the whole yada stack for a few weeks on a side project
overall it’s exactly what i’m looking for in a web stack, it’s just got a few rough edges still. i’m actually quite surprised something like this hasn’t existed for a long long time
i think there might be a schema specification issue — i’m still getting
:error {:access-control {:realms {"default" {:authentication-schemes [{(not (namespace :authenticate)) invalid-key, (not (namespace :authorization)) invalid-key}]}}}}
during resource validation. if i make the map {... :foo/authenticate ... :foo/authorization ...}
i don’t get the error, but then obviously https://github.com/juxt/yada/blob/master/src/yada/security.clj#L104 fails at runtime