All Projects → Silvanite → Brandenburg

Silvanite / Brandenburg

Licence: mit
Laravel Authentication Package

Projects that are alternatives of or similar to Brandenburg

Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+3397.47%)
Mutual labels:  laravel, laravel-5-package, authorization, auth, permissions, acl, roles
Sentinel
A framework agnostic authentication & authorization system.
Stars: ✭ 1,354 (+1613.92%)
Mutual labels:  laravel, authentication, authorization, auth, permissions, roles
Laravel Auth
A powerful authentication, authorization and verification package built on top of Laravel. It provides developers with Role Based Access Control, Two-Factor Authentication, Social Authentication, and much more, compatible Laravel’s standard API and fully featured out of the box.
Stars: ✭ 128 (+62.03%)
Mutual labels:  laravel, authentication, authorization, permissions, roles
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+3307.59%)
Mutual labels:  laravel, laravel-framework, authentication, roles, users
Laratrust
Handle roles and permissions in your Laravel application
Stars: ✭ 1,799 (+2177.22%)
Mutual labels:  laravel, authorization, permissions, acl, roles
Shinobi
👺 Simple and light-weight role-based permissions system for Laravel's built in Auth system.
Stars: ✭ 349 (+341.77%)
Mutual labels:  laravel, authentication, auth, permissions, roles
Appy Backend
A user system to bootstrap your app.
Stars: ✭ 96 (+21.52%)
Mutual labels:  authentication, authorization, permissions, users
Accesscontrol
Role and Attribute based Access Control for Node.js
Stars: ✭ 1,723 (+2081.01%)
Mutual labels:  authorization, permissions, acl, roles
Laravel Governor
Manage authorization with granular role-based permissions in your Laravel Apps.
Stars: ✭ 131 (+65.82%)
Mutual labels:  laravel, authorization, permissions, roles
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+191.14%)
Mutual labels:  laravel, laravel-5-package, laravel-framework, authentication
Simpleacl
Simple ACL for PHP
Stars: ✭ 105 (+32.91%)
Mutual labels:  authorization, auth, permissions, acl
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (+72.15%)
Mutual labels:  laravel, authorization, permissions, acl
Rbac
Hierarchical Role Based Access Control for NodeJS
Stars: ✭ 857 (+984.81%)
Mutual labels:  authentication, authorization, auth, permissions
Think Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in ThinkPHP 6.0 .
Stars: ✭ 155 (+96.2%)
Mutual labels:  authorization, permissions, acl, roles
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (-34.18%)
Mutual labels:  laravel, authentication, authorization, auth
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+45.57%)
Mutual labels:  permissions, acl, roles, authorization
Casbin4D
An authorization library that supports access control models like ACL, RBAC, ABAC in Delphi
Stars: ✭ 25 (-68.35%)
Mutual labels:  permissions, acl, auth, authorization
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (+411.39%)
Mutual labels:  laravel, authentication, authorization, acl
Php Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in PHP .
Stars: ✭ 865 (+994.94%)
Mutual labels:  authorization, auth, acl, roles
Sudo Su
Laravel package to easily login as other users during development.
Stars: ✭ 554 (+601.27%)
Mutual labels:  laravel, laravel-5-package, authentication

Brandenburg

Laravel Authorization Package

Latest Version on Packagist Build Status

A opinionated Authorization package to closely integrate with standard Laravel Gates. It differs from other authorization packages by using hard-coded permissions defined within gate policies, rather than duplicating them within the Database.

TLDR; This package provides Users with Roles which are granted access to permissions (Laravel Gates).

Version compatibility

Laravel Brandenburg
<=5.7.x 1.1.x
>=5.8.x 1.2.x
^6.0 1.3.x
^7.0 1.4.x

Installation

composer require silvanite/brandenburg

This package uses auto-loading in Laravel 5.5 of both the service provider and the BrandenburgPolicy Facade

For Laravel 5.1 - 5.4 load the Service Provider and Facade.

// config/app.php
'providers' => [
    ...
    Silvanite\Brandenburg\Providers\BrandenburgServiceProvider::class,
];

'aliases' => [
    ...
    'BrandenburgPolicy' => Silvanite\Brandenburg\Facades\PolicyFacade::class,
],

Three additional tables are required to enable User Roles. These will be installed automatically when you run the migrations. See the migration in this repository's source code for details about the tables created.

php artisan migrate

If you are not going to use Brandenburg's default migrations, you should change the ignoreMigrations option in the configuration file. You may export the default migrations using:

php artisan vendor:publish --tag=brandenburg-migrations

Usage

This package provides two traits. The main trait is intended for your user model which enabled model relationships.

use Silvanite\Brandenburg\Traits\HasRoles;

class User
{
    use HasRoles;
    ...
}

The second Trait ValidatesPermissions can optionally be used in your AuthServiceProvider when writing Gates. It can be used to stop users from getting locked out or to make some permissions optional by allowing access to a permission if no user in the system has been given access to it.

// AuthServiceProvider.php

if ($this->nobodyHasAccess('create-articles')) {
    return true;
};

// Check if the user has access
...

Creating Roles

Use the Silvanite\Brandenburg\Role model to create and manage user roles.

$editor = Silvanite\Brandenburg\Role::create([
    'name' => 'Editor',
    'slug' => 'editor',
]);

Creating Permissions

All Gates defined within your application will automatically be available as Permissions, there is no need/way to create these specifically in the database. Please see the Laravel Gates documentation for additional information.

Managing Roles and Permissions

All permissions are assigned by providing the key defined by your Gate. They can be granted and revoked.

// Grant access
$editor->grant('create-articles');

// Revoke access
$editor->revoke('create-articles');

A couple of additional helper methods provide a convenient way to manage permissions.

// Grant access to a set of permissions and remove all other permissions
$editor->setPermissions([
    'create-articles',
    'read-articles',
    'update-articles',
    'delete-articles',
]);

// Revoke all permissions
$editor->revokeAll();

You can see which permissions a given role has by accessing the permissions attribute.

$editorPermissions = $editor->permissions;

// returns ['create-articles', 'read-articles', 'update-articles', 'delete-articles']

Assigning/Removing Roles

Roles can be assigned/removed directly from the User model (provided the HasRoles trait is used). You can either pass in the Role model or the slug of the role.

// Using slug
$user->assignRole('editor');
$user->removeRole('editor');

// Using model
use Silvanite\Brandenburg\Role;

$user->assignRole(Role::first());
$user->removeRole(Role::first());

There is also a helper method to sync roles (or you can simply use the eloquent relationship itself).

$user->setRolesById([1, 3, 4]);

// Same as
$user->roles()->sync([1, 3, 4]);

Validating Access Rights

Within your Gate definition you can validate if a given user has access to a specific permission, which will be based on the user Role(s).

$canCreateArticle = $user->hasRoleWithPermission('create-articles');

Outside of your Gate definitions you should use the standard Laravel Gate methods and helpers to check if a user has access rights. See the Laravel Documentation for more details.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Run the tests: ./vendor/bin/phpunit
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request

Support

If you require any support please contact me on Twitter or open an issue on this repository.

License

GPL

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].