Search by

destroking / user-roleright

destroking95

User Role and Right Management With Route

Package info

github.com/bhautik-bhuva/user-roleright-laravel

Language:Blade

pkg:composer/destroking/user-roleright

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.86 2026-11-30 08:28 UTC

README

User Role and Right Management With Route for Laravel applications.

The package provides single sign-on (SSO) for Laravel applications. See SSO setup and contract for database-stored settings, dedicated key generation, testing and deployment.

Features

  • Manage users, roles, permissions, and module actions
  • Interface access management (Backend, Frontend, API)
  • Dynamic route registration & middleware protection
  • Automated database migrations and seeders (DatabaseSeeder, ModuleActionDataSeeder, InterfaceAccessDataSeeder, UserDataSeeder)
  • Simple command-driven installation, update, and removal
  • Single sign-on with encrypted database-stored configuration, dedicated keys, timestamp validation, and replay protection

Installation

  1. Add the package repository to the composer.json file in your root project in case of private repo:
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/bhautik-bhuva/user-roleright-laravel.git"
    }
]
  1. Require the package via Composer:
composer require destroking/user-roleright

For an existing installation, update the package name and repository in the host application's composer.json and run composer update. Update PHP imports, provider registrations, and copied Blade snippets to use RoleRight\UserAccess. Clear Laravel's cached views and configuration, then run php artisan useraccess:update. The removal command rolls back package migrations.

  1. Initialize the package configuration:
php artisan useraccess:init-config

What useraccess:init-config does:

  • Runs php artisan useraccess:install to migrate tables and run all package seeders (DatabaseSeeder).
  • Normally asks six questions with SSO selected: configure SSO, SSO provider API URL, platform website, Super Admin email, layout file, and CSS framework.
  • Detects the user table from the default authentication provider and uses content as the initial yield section. Existing saved table/yield settings are retained.
  • Selects the full layout file in one question, instead of asking separately for its folder and filename. Leave the Super Admin email blank to retain existing assignments.
  • Stores layout, yield containers, and package options in rbac_configuration under useraccess_config.
  • If SSO setup is selected, runs useraccess:sso-install and stores its settings separately under useraccess_sso_config.
  • Publishes assets and adds remove-useraccess and update-useraccess helper scripts to composer.json.

For custom user tables, yield sections, or all SSO overrides, use:

php artisan useraccess:init-config --advanced

Missing or ambiguous settings trigger an extra question instead of being guessed. Rerunning initialization retains the saved Super Admin ID, menu migration state, and other existing package options unless you explicitly change them.

Available Commands

1. Install Package

php artisan useraccess:install
  • Creates required database tables (interface_access, module_action, roles, role_action, right_action, user_role_mapping, menu_procedure).
  • Executes package database seeders (DatabaseSeeder).
  • Loads dynamic routes through the package service provider; no manual inclusion in routes/web.php is required.
  • Publishes assets to public/assets/vendor/useraccess.
  • Adds helper scripts to composer.json.

2. Update Package

The UserAccess Settings page displays an update notice when Packagist lists a newer stable version. Checks are cached for 15 minutes.

When upgrading from an older release, update the Composer package first, then run the package upgrade command to create missing tables (including rbac_configuration) and import the legacy configuration:

composer update destroking/user-roleright
php artisan useraccess:update

or via Composer script:

composer run update-useraccess
  • Re-runs database migrations and verifies missing table structures.
  • Executes DatabaseSeeder to refresh/seed all data files in Database/Seeders.
  • Re-publishes package assets. The service provider handles dynamic route registration.

Menu sequence

From Menu Management, open Menu Sequence (/useraccess/menu/sequence). Drag the handles on this dedicated page and click Save sequence to save the full module order. Use Reset changes to undo unsaved moves. Arrow buttons and the handle's arrow keys also move modules. The controls use the existing menu-update permission. If modules have been added or removed since loading the page, reload before saving again.

In Menu Management, create or edit a menu and set Menu Label Sequence to the desired main module position (starting at 1). Saving a changed sequence moves every action with that module_label together, shifts the other modules, and saves consecutive sequences across the entire module_action table in one transaction. Hidden and inactive actions retain their module's sequence too. Positions beyond the last module place the module at the end. Existing gaps and duplicate positions are normalized when the sequence or module label changes. For example, moving module C from position 3 to 1 changes A, B, C to C, A, B.

3. Remove Package

php artisan useraccess:remove

or via Composer script:

composer run remove-useraccess
  • Resets package database migrations (migrate:reset).
  • Safely removes dynamic route imports from routes/web.php.
  • Deletes published vendor assets from public/assets/vendor/useraccess.
  • Cleans up package scripts (remove-useraccess and update-useraccess) from composer.json.

4. Configure single sign-on

php artisan useraccess:sso-install
php artisan route:clear

Normal SSO setup asks only for the SSO provider’s HTTPS API base URL and the exact website value registered with the provider. On first setup it detects the Eloquent session guard and unambiguous admin.login/login and admin.dashboard/dashboard routes, derives the signed-in landing path, and selects the configured persistent cache (or a configured file store for a single host). If detection is missing or ambiguous, it asks for just that setting. Use --advanced to select the local user column that matches the provider’s account identifier. For example, if the provider sends acct-0042, configure external_id and store acct-0042 in that column on the matching user. See the worked setup example for the provider URL, website, and landing route values.

Setup stores SSO settings in rbac_configuration with config_key=useraccess_sso_config. The dedicated shared key is encrypted in config_value using this application's APP_KEY. No receiving-project SSO controller, route, service, config file, or SSO environment variables are needed.

A dedicated key is generated automatically on first normal setup and displayed once after saving. Reruns retain the existing key and custom settings. Configure the same dedicated key in the SSO provider using its per-application key settings, then reload its configuration. Reserve each application’s APP_KEY for its own Laravel encryption.

Setup leaves SSO disabled. After both applications are configured, enable the saved settings:

php artisan useraccess:sso-install --enable

To disable SSO without changing the key:

php artisan useraccess:sso-install --disable

For custom fields, routes, cache, local active-account checks, or an existing key:

php artisan useraccess:sso-install --advanced

The advanced hidden key prompt retains the saved key when left blank; on first setup a blank prompt generates a key. Normal reruns preserve saved active-account filters. Reconfiguration disables SSO. To explicitly rotate an existing key use php artisan useraccess:sso-install --generate-key, then update the SSO provider. Enable, disable, and key-generation flags must be used separately. Unreadable saved settings are not overwritten or silently assigned a replacement key.

SSO behavior and verification

The package registers public GET /sso/callback?token=... before normal login checks and preserves it during menu filtering. It decrypts the dedicated-key AES-256-GCM v1. handoff, rejects future timestamps and handoffs aged 60 seconds or more, and verifies the account and website with the provider’s POST /api/v1/sso/auth-check endpoint.

UUID_SHORT stays a decimal string. Successful verification maps exactly one existing local account, retains its existing plugin permissions, regenerates the normal session ID, and redirects to a clean landing URL. SSO never updates or clears the existing remember tokens. Invalid handoffs create no authenticated session; password login continues to work.

Use database sessions for the plugin's route discovery and a shared atomic replay cache for multiple hosts. Keep route caching disabled. The callback takes precedence over an existing project callback, so leave old project SSO files in place during testing and remove them only after live acceptance.

Run the package's isolated tests from a consuming Laravel project:

vendor/bin/phpunit -c vendor/destroking/user-roleright/phpunit.xml
php artisan route:list --path=sso

The setup tests use an isolated Laravel app, database query fixtures, and mocked SSO settings persistence; they do not run live migrations or contact the SSO provider. They check prompt counts, automatic defaults/key generation, saved-setting retention, explicit key rotation, advanced overrides, and safe failure behavior. Verify a real launch from the SSO provider, local permission restrictions, inactive or unmapped accounts, replay and expiry, and password login on the deployed hosts before relying solely on the plugin. See SSO.md for all stored fields, encryption format, logging controls, account mapping, and package release instructions.

Usage within Blade Templates

Extend Layout:

@extends('laravelMain::' . $layout_file)

Section Container:

Replace Code in Layout File,
  @{{ $slot }}
With below code
  @if (request()->is('useraccess/*') || request()->is('useraccess'))
      <div class="container mx-auto">
          @@yield('content')
      </div>
  @else
      <div class="container mx-auto">
          @{{ $slot }}
      </div>
  @endif

Useful URLs

  • Menu Management Settings: https://your-domain.com/useraccess/setting
  • Route Sync / Migration: https://your-domain.com/useraccess/menu/migrate
  • Access Types: https://your-domain.com/useraccess/interface-access/list

License

MIT