I am having issues using access control using cerbos

I have imported the example implementation of access controll using cerbos and it has code as follows :
kapa.ai
kapa.ai329d ago
Hi @srinivasbhuvanagiri. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
extended-salmon
extended-salmon329d ago
i am not able to access resources
kapa.ai
kapa.ai329d ago
---------------------- It seems like you haven't provided the code you're referring to. However, based on the information extracts, I can provide you with an example implementation of access control using Cerbos in a refine project. First, install Cerbos:
npm install cerbos
npm install cerbos
Then, create a Cerbos object in the App.tsx file and define it in <Refine>:
import { Cerbos } from "cerbos";

const cerbos = new Cerbos({
hostname: "<https://demo-pdp.cerbos.cloud",> // The Cerbos PDP instance
playgroundInstance: "WS961950bd85QNYlAvTmJYubP0bqF7e3", // The playground instance ID to test
});

// ...

<Refine
// ...
accessControlProvider={{
can: async ({ action, params, resource }) => {
const cerbosPayload = {
principal: {
id: "demoUser", // Fake a user ID
roles: [role],
attr: {},
},
resource: {
kind: resource,
instances: {
[params?.id || "new"]: {
attr: params,
},
},
},
actions: [action],
};
const result = await cerbos.check(cerbosPayload);
return Promise.resolve({
can: result.isAuthorized(params?.id || "new", action),
});
},
}}
// ...
/>
import { Cerbos } from "cerbos";

const cerbos = new Cerbos({
hostname: "<https://demo-pdp.cerbos.cloud",> // The Cerbos PDP instance
playgroundInstance: "WS961950bd85QNYlAvTmJYubP0bqF7e3", // The playground instance ID to test
});

// ...

<Refine
// ...
accessControlProvider={{
can: async ({ action, params, resource }) => {
const cerbosPayload = {
principal: {
id: "demoUser", // Fake a user ID
roles: [role],
attr: {},
},
resource: {
kind: resource,
instances: {
[params?.id || "new"]: {
attr: params,
},
},
},
actions: [action],
};
const result = await cerbos.check(cerbosPayload);
return Promise.resolve({
can: result.isAuthorized(params?.id || "new", action),
});
},
}}
// ...
/>
This example demonstrates how to use refine and Cerbos to simplify access control management throughout your application. For more information, refer to the refine Access Control Provider documentation (https://refine.dev/docs/api-reference/core/providers/accessControl-provider/) and the Cerbos example source code (https://github.com/refinedev/refine/tree/master/examples/access-control-cerbos). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai329d ago
<@1016596495673339954> kapa.ai is still learning and improving, please let us how it did by reacting below
extended-salmon
extended-salmon329d ago
No description
extended-salmon
extended-salmon328d ago
can anyone please help me i am not able to implement cerbos role based authorization
afraid-scarlet
afraid-scarlet328d ago
Hey @srinivasbhuvanagiri have you tried using console.log to get information about what's not working? Maybe try to get some information about the answers that the cerbos client library provides like: console.log({ action, params, resource, result }) I think check the parameters that are being passed to cerbos would also make sense. Or using the library in isolation first to understand how it's working.
extended-salmon
extended-salmon328d ago
where do we define policies when we are using refine @bastianwegge how do we define policies
afraid-scarlet
afraid-scarlet328d ago
@srinivasbhuvanagiri everything related to your authorization will be defined within cerbos. Refine only leverages the library you're including to call a specific command like const result = await cerbos.check(cerbosPayload);. The result of that command can then be used like shown above by kapa.ai (like result.isAuthorized). accessControlProvider is basically a method to say "I want external authorization, here's how it looks like"
extended-salmon
extended-salmon326d ago
i am using cerbos admin api so how can i integrate it with refine @bastianwegge can you please help me out with cerbos admin api i am creating policies dynamically so i am not able to configure it with refine can anyone help me
afraid-scarlet
afraid-scarlet326d ago
@srinivasbhuvanagiri please either a concrete question or provide more information to work with, like some code inside of a codesandbox or on GitHub, otherwise we won't be able to help. Maybe take some time to read about the integration or look at the example here (https://refine.dev/docs/examples/access-control/cerbos/).
More Posts
Unhandled Error in logout: refine always expects a resolved promise.```logout: async ({ email, password }) => { localStorage.removeItem("auth"); return ConfigProvider ant designI am still struggeling to customize the ant design button on the login page by adding a provider conLog Out User If JWT has expired.@kapa.ai , Lets say i am logged in as a user in my refine app and my jwt token has expired, then wheAm I stupid or whatAm I stupid or what? `const { data, error } = useList<ApiData, HttpError>({...})` - type of `error`So I installed Refine with all theSo, I installed Refine with all the necessary dependencies. However I'm trying to edit(Sider) of thefiltersHow to filter the created at field with between operatorHi everyone I m new to refine and IHi everyone, I'm new to refine and I couldn't find anywhere a nice way to make a useSelect depend onDependency between two useSelectIs there any way to acheive a Select form item depending on another one. Suppose we have tow Select Frontend in React to refine.devHi , i'm a new bie , can someone give me an hint in how to connect a Frontend in React to refine.devRequest for Assistance with useDataGridHello, I hope this message finds you well. I am reaching out because I am currently facing an issueCustom Search in MUI Datagrid@kapa.ai , I have a list page in which by using useDataGrid, i have created a mui datagrid for my reCustomizing auth pagesHi, Can someone tell me how to customize Auth pages? For example: In the login page, I don't want toDoes it make sense to use Refine without using Inferencer?Should I choose another framework if I am not interested in Inferencer?Navigating Data Export with the useExport Hook in Refine FrameworkHello, I am currently using the Refine Framework and have some questions regarding the useExport hoHow to integrate refine with an already existing application that has the same functionality ofI have an already built application and I wish to integrate it with refine for the CRUDE functionaliRefine type inference from SupabaseHow to get Supabase type safety in Refine data hooksApart from Crude can someone also addApart from Crude can someone also add functionalities to the refine application?. I have an already Hide refresh button in edit page@kapa.ai , I am using Edit of @refinedev/mui, in which a refresh button is provided by default. I doSome queries are fetched multiple times not using the cached queryIn my current project some queries are executed multiple times, fetching data again without using thWhere to replace generated code?The following inferencer code should be replaced where exactly in my app.tsx. Also how do I get rid