Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
ra-auth-acl
Advanced tools
Provide a small ACL framework to manage resources views access based on pre-defined roles.
npm install --save-dev ra-auth-acl
# or
yarn add ra-auth-acl
This library relies on the existing React Admin permission management, which allows to get permissions from an authenticated user.
<ResourceWithPermissions>
instead of the react-admin <Resource>
component.import React from 'react';
import { Admin } from 'react-admin';
import authProvider from './authProvider';
import posts from './posts';
import comments from './comments';
render(
<Admin authProvider={authProvider}>
{permissions => [
<ResourceWithPermissions name="posts" permissions={permissions} {...posts} />,
<ResourceWithPermissions name="comments" permissions={permissions} {...comments} />,
]}
</Admin>
);
AUTH_GET_PERMISSIONS
verb:// authProvider.js
import { AUTH_GET_PERMISSIONS } from 'react-admin';
export default (type, params) => {
// ...
if (type === AUTH_GET_PERMISSIONS) {
return Promise.resolve({
posts: {
// Use the resource `name` prop as identifier
enabled: true,
list: true,
create: false,
edit: false,
show: true,
},
comments: {
enabled: false, // This won't show the resource at all
custom: true, // You can pass your own custom keys if needed
},
});
}
};
The ACL works with five default permissions, all false
by default:
You can go with your custom permissions and use the hasAccess
helper to customize your resources:
import { hasAccess } from 'ra-auth-acl';
export const UserList = ({ permissions, ...props }) => (
<List {...props}>
<Datagrid rowClick={hasAccess(permissions, 'users.edit') ? 'edit' : 'show'} expand={<UserEditEmbedded />}>
<TextField source="id" />
<TextField source="name" />
{hasAccess(permissions, 'users.custom') && <TextField source="role" />}
</Datagrid>
</List>
);
Instead of building the permissions list each time, you can store the role in the local storage or in a JSON Web Token, and request the permissions list at runtime:
// authProvider.js
import { AUTH_GET_PERMISSIONS } from 'react-admin';
import { buildFullAccessFor } from 'ra-auth-acl';
const permissions = {
admin: {
...buildFullAccessFor(['posts', 'comments', 'users', 'tags']),
},
user: {
...buildFullAccessFor(['posts', 'comments', 'tags']),
},
};
export default (type, params) => {
if (type === AUTH_GET_PERMISSIONS) {
const role = localStorage.getItem('role'); // Might be async request!
return Promise.resolve(permissions[role]);
}
};
This library is licensed under the MIT License, sponsored and supported by marmelab.
FAQs
Access Control List helper for React Admin
We found that ra-auth-acl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.