Git Product home page Git Product logo

fiber-casbin's Introduction

Hi, I'm Alireza Salary

How to reach me 📭

Linkedin URL Stackoverflow URL Outlook URL Gmail URL Skype URL Telegram URL

Github Stats Top Langs

fiber-casbin's People

Contributors

arsmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fiber-casbin's Issues

What do you think about support for route params

Hello

Take the following code for example

 app.Delete("/blog/:id",
    authz.RequiresPermissions([]string{"blog:create", "blog:delete"}, fibercasbin.AtLeastOne),
    func(c *fiber.Ctx) error {
      // your handler
    },
  )

I may want to set up the permission such that I would love to actually check if the user has the role to delete the blog post with id "123". Is that something you plan to support?

How to update casbin Rules When i AddPolicy/RemovePolicy

Hey...

func IndexTest(ctx *fiber.Ctx) error {

	return ctx.Status(http.StatusOK).JSON("hello world!")
}

func IndexDemo1(ctx *fiber.Ctx) error {
	enforcer := config.Enforcer
	if ok, _ := enforcer.AddPolicy("admin", "/v1/test", "GET"); !ok {
		return ctx.Status(http.StatusOK).JSON("Policy exist")
	}
	return ctx.Status(http.StatusOK).JSON("add success")
}

func IndexDemo2(ctx *fiber.Ctx) error {
	enforcer := config.Enforcer
	if ok, _ := enforcer.RemovePolicy("admin", "/v1/test", "GET"); !ok {
		return ctx.Status(http.StatusOK).JSON("Policy no exist")
	}
	return ctx.Status(http.StatusOK).JSON("delete success")
}

And the CasbinMiddleware code like this:

func Casbin() *fibercasbin.CasbinMiddleware {
	db := config.DB
	adapter, _ := gormadapter.NewAdapterByDBWithCustomTable(db, &models.CasbinRule{})
	authz := fibercasbin.New(fibercasbin.Config{
		ModelFilePath: "config/rbac_model.conf",
		PolicyAdapter: adapter,
		Unauthorized: func(c *fiber.Ctx) error {
			return c.Status(http.StatusUnauthorized).JSON(fiber.Map{"message": "Unauthorized...", "status_code": 401})
		},
		Forbidden: func(c *fiber.Ctx) error {
			return c.Status(http.StatusNotFound).JSON(fiber.Map{"message": "Forbidden ...", "status_code": 404})
		},
		Lookup: func(c *fiber.Ctx) string {
			// get subject from BasicAuth, JWT, Cookie etc in real world
			return "admin"
		},
	})
	//adapter.LoadPolicy() // model Model 
	return authz
}

test the method Demo1 or Demo2 , the CasbinMiddleware not immediate effect。

v.Get("/test", authz.RoutePermission(), IndexTest)

Can your help?

README.md update needed for lookup function config

Details

Howdy there 👋 Friendly heads up that it looks like the function to perform a lookup within the fibercasbin config was changed to actually use the field Lookup rather than SubLookupFn. In case anyone else runs into the same issue, wanted to give the heads up to update that line in the docs. 😄

README.md

 SubLookupFn: func(c *fiber.Ctx) string {
          // fetch authenticated user subject
 }

Fixed reference

 Lookup: func(c *fiber.Ctx) string {
          // fetch authenticated user subject
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.