casbin / casbin.js

An authorization library that supports access control models like ACL, RBAC, ABAC in Frontend Javascript
https://casbin.org/docs/en/frontend
Apache License 2.0
160 stars 37 forks source link

Behavior of client side casbin service #277

Closed dovranJorayev closed 11 months ago

dovranJorayev commented 11 months ago

Help me please to understand how casbin.js client side library will behave if access related data will be live on backend side... Do all authorizer.can("read", "data1") calls will make request for a server or it is somehow caching the data or load all data related to app on initialization step? Because i guess it would decrease UX if every time will knock backend when need to interact with interface

casbin-bot commented 11 months ago

@nodece @Shivansh-yadav13

hsluoyz commented 11 months ago

@dovranJorayev see docs: https://casbin.org/docs/frontend/

dovranJorayev commented 11 months ago

@dovranJorayev see docs: https://casbin.org/docs/frontend/

I know if i will use manual option it will be not such case. But i am interested in that use-case

// Set your backend Casbin service URL
const authorizer = new casbinjs.Authorizer(
    'auto', // mode
    {endpoint: 'http://your_endpoint/api/casbin'}
);

const result = authorizer.can("read", "data1"); // <------ Promise here

I don't get how it will process. Does all authorizer.can(...) calls will comunicate with backend or it load all permissions once event in such mode. Or it has something like caching?

hsluoyz commented 11 months ago

@dovranJorayev IIRC, it only loads policy from remote once, it doesn't call RESTful API for each .can() method. For details, you need to see the source code

dovranJorayev commented 11 months ago

@dovranJorayev IIRC, it only loads policy from remote once, it doesn't call RESTful API for each .can() method. For details, you need to see the source code

Thanks a lot @hsluoyz , this point was unclear for me until now