1

How do I setup dynamic RBAC using Casbin with Beego? I am using MySQL database via Beego ORM and able to login. However, I want to setup roles and permissions.

I also explored gorbac but I am interested to use Casbin.

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
Prashant
  • 2,005
  • 3
  • 17
  • 24

1 Answers1

1

There's an authorization middleware for Beego here: https://github.com/casbin/beego-authz. You can read the README.md to know how to do it. And for your requirement:

  1. Please use the Xorm Adapter or Gorm Adapter to store Casbin policy into MySQL. We also have Beego ORM Adapter but it has some limitations.

  2. You want to setup roles, so you can use Casbin's RBAC model. You can start with the official RBAC example (model + policy). If your resource is just the RESTful path, you can also refer to the RESTful example.

hsluoyz
  • 2,739
  • 5
  • 35
  • 59
  • Thanks @Yang Luo. Do you have an example repository where I can look up the implementation? I am new to Beego and casbin and just trying it out. – Prashant Jul 20 '18 at 08:57
  • The Beego middleware itself already contains an example, see the main.go file: https://github.com/casbin/beego-authz/blob/master/main.go – hsluoyz Jul 20 '18 at 12:35
  • Any persistence example? – Prashant Jul 25 '18 at 14:35
  • See this example: https://github.com/aixj1984/website-gateway/blob/299e1ea91af488e434a3c0f475270484224be13e/enforcer/casbin.go#L9 – hsluoyz Jul 25 '18 at 15:02