portico_auth_roles 1.0.0 copy "portico_auth_roles: ^1.0.0" to clipboard
portico_auth_roles: ^1.0.0 copied to clipboard

Role-Based Access Control (RBAC) metadata and assignment system.

Portico Auth Roles #

Portico Auth Roles License: MIT

Description of the image

A flexible Role-Based Access Control (RBAC) system for managing user permissions and assignments. This package provides a robust way to define roles and associate them with users, either globally or scoped to specific resources.

Features #

  • Role Definitions: Create and manage roles with display names, descriptions, and activation states.
  • Scoped Assignments: Assign roles to users globally or scoped to specific resources (e.g., org:123, project:abc).
  • Reactive Storage: Compatible with multiple storage backends (SQLite, YAML, Memory) with automatic updates.
  • Role Lifecycle: Deactivate roles to revoke access across all users without deleting assignment history.

Getting started #

Add this package to your pubspec.yaml:

dependencies:
  portico_auth_roles: ^1.0.0

Interactive Web Simulator #

Experience the full capabilities of the Portico Auth ecosystem without setting up a backend. The Web Simulator runs the entire stack (Client, Server, and Storage) directly in your browser.

Usage #

1. Initialize the Manager #

import 'package:portico_auth_roles/portico_auth_roles.dart';

// Use InMemory storage for testing/prototyping
final storage = AuthRolesInMemoryStorage();
final manager = AuthRoleManager(storage);

2. Manage Roles #

// Create a global 'admin' role
await manager.createRole(
  name: 'admin',
  displayName: 'Administrator',
  description: 'Full system access',
);

// Create a 'moderator' role
await manager.createRole(
  name: 'moderator',
  displayName: 'Moderator',
  description: 'Can moderate content',
);

3. Assign Roles (Global & Scoped) #

const userId = 'user_123';

// Assign global admin role
await manager.assignRoleToUser(
  userId: userId,
  roleName: 'admin',
);

// Assign moderator role for a specific resource (Scoped)
await manager.assignRoleToUser(
  userId: userId,
  roleName: 'moderator',
  scope: 'resource_456',
);

4. Check Roles and Scopes #

// Get all unique active role definitions assigned to the user
final roles = await manager.getUserRoles(userId);
print(roles.map((r) => r.name)); // ['admin', 'moderator']

// Get detailed assignments (including scopes)
final assignments = await manager.getUserAssignments(userId);
for (final assignment in assignments) {
  print('${assignment.roleName} (Scope: ${assignment.scope ?? "Global"})');
}

Examples #

1
likes
160
points
73
downloads

Publisher

verified publishermcdole.org

Weekly Downloads

Role-Based Access Control (RBAC) metadata and assignment system.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

equatable, json_annotation

More

Packages that depend on portico_auth_roles