@koshirepo/auth-core
v0.2.1
Published
Shared types, errors and RBAC/ABAC policy evaluation for the auth library. No runtime dependencies.
Readme
@koshirepo/auth-core
Shared building blocks of the auth library. No dependencies, and no Node or DOM globals, so it runs on the server, in the browser and on edge runtimes.
- Typed errors with stable codes:
AuthErrorand its subclasses,isAuthError,errorFromBody. - RBAC:
defineRbac, with role and permission names checked at compile time. - ABAC:
definePolicy,allow,denyandcreateAuthorizer. Policies are functions of subject, action, resource and context. Deny wins, and the default is deny. - Audit event types, identity types and the HTTP wire types shared by server and client.
Installation
npm install @koshirepo/auth-coreimport { createAuthorizer, defineRbac, definePolicy, deny } from '@koshirepo/auth-core';
const rbac = defineRbac({
permissions: ['invoice:read', 'invoice:write'],
roles: { viewer: { grants: ['invoice:read'] }, editor: { inherits: ['viewer'], grants: ['invoice:write'] } },
});
const authorizer = createAuthorizer({ rbac });
authorizer.can({ id: 'u1', roles: ['viewer'] }, 'invoice:write'); // falseSee the API reference.
