casbin_example icon indicating copy to clipboard operation
casbin_example copied to clipboard

We may need a sample request for beginner

Open pomcho555 opened this issue 3 years ago • 0 comments

This repository is so helpful to understand casbin works under the gin web application. But, there are no sample requests to feel RBAC. So I wrote a tiny snippet for beginner. You can adapt it into README, if you like it.

  1. Login as Bob

    curl -c cookie.txt -d "username=bob" -d "password=123" "http://localhost:8081/user/login"
    
  2. Read resource

    curl -b cookie.txt http://localhsot:8081/api/resource
    

    You can get a following output

    {“code”:1,“message”:“read resource successfully”,“data”:“resource”}
    
  3. Write resource

    curl -XPOST -b cookie.txt localhost:8081/api/resource
    

    You can be denied a request because of the defined policy

    {“code”:0,“message”:“forbidden”,“data”:null}
    

pomcho555 avatar May 13 '21 08:05 pomcho555