Fork me on GitHub
#yada
<
2016-11-15
>
tcoupland10:11:36

hopefully this idea will go down a bit better 🙂

rajdevireddy11:11:27

Hi all, I am trying to figure out how :access-control works. Have not had success yet, I have read security chapter in yada manual, but I guess I am doing something wrong here. Appreciate any help I can get on this. Here is my resource.

(defn hello-routes []
  ["/hello" (yada/resource  {:id          :test-resource/hello
                             :description "Says Hello!"
                             :produces    "text/plain"
                             :access-control {:realm "accounts"
                                              :scheme "Basic"
                                              :verify (fn [[user password]]
                                                          (println "Verify function invoked")
                                                          nil)}
                            :methods {:get {:response "Hello world!!!\n"}}})]) 
But that verify function never get invoked.

Rachel Westmacott13:11:19

you might need an :authorization key in the :access-control map

Rachel Westmacott13:11:54

from memory when I used access-control I found that authentication and authorization seemed to be in syzygy

rajdevireddy15:11:10

Thanks for the response. This is the hello-world resource from the edge app on github. For some reason the call to /hello goes through. I was expecting it to return a HTTP 401.

malcolmsparks15:11:25

one thing is that "Basic" is implemented like this

malcolmsparks15:11:55

which means that verify is only called if there are credentials passed in the Authorization request header

rajdevireddy15:11:50

I was not passing anything and the request went through to the resource 🙂. I will try to set some in the header.

malcolmsparks15:11:29

now, this is not like the way most web frameworks do it - as @peterwestmacott rightly points out, you need to add an :authorization entry

malcolmsparks15:11:50

Authentication by itself with not cause a 401 Unauthorized error status

rajdevireddy15:11:05

Thanks much for the response, trying that now.

malcolmsparks15:11:31

I've just posted a snippet from a previous conversation on slack which might throw some light on the design

rajdevireddy16:11:04

Awesome! working now. Thanks much for all the help @malcolmsparks and @peterwestmacott

(defn hello-routes []
  ["/hello" (yada/resource  {:id          :test-resource/hello
                             :description "Says Hello!"
                             :produces    "text/plain"
                             :access-control
                                              {:authorization {:methods {:get :Some-Permission-Name}}
                                               :realm "edgetest"
                                               :scheme "Basic"
                                               :verify (fn [[user password]] (println "Verify function invoked") nil)
                                               }
                            :methods
                             {:get {:response "Hello world!!!\n"}}}
                            )])