Download the PHP package thinkstudeo/laravel-rakshak without Composer
On this page you can find all versions of the php package thinkstudeo/laravel-rakshak. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thinkstudeo/laravel-rakshak
More information about thinkstudeo/laravel-rakshak
Files in thinkstudeo/laravel-rakshak
Package laravel-rakshak
Short Description An authentication library for Laravel.
License MIT
Informations about the package laravel-rakshak
Rakshak - Two Factor Authentication & Authorization for Laravel 5.7+
This package extends the authentication and authorization in a Lavarel application.
- Roles and Abilities for granular authorization.
- Two Factor Authentication functionality.
- Auth views, Blade directives and Route middleware.
Contents
- Rakshak - Two Factor Authentication & Authorization for Laravel 5.7+
- Contents
- Installation
- Config
- Usage
- Two Factor Authentication
- HasRakshak trait
- Adding and Retracting Ability to a Role
- Assigning and Retracting Role to User
- Check if the User has role
- Check if the User has any of given multiple role
- Check if the User has ability
- Check if the User has any of given multiple abilities
- Roles and Abilities
- Route Middleware
- Blade Directives
- Changelog
- Testing
- Security
- Contributing
- Credits
- License
Installation
Then use the artisan command to install/integrate the package with your Laravel application.
The artisan command will:
- register the authentication routes
- provide the authentication views (very similar to the
auth:make
command) - publish the views for managing crud for Roles, Abilities and Rakshak settings
- register two middlewares
rakshak.2fa
to verify otp, providing 2fa protection for routesrole
to provide authorization protection for routes
- publish the package config
rakshak.php
to theconfig
folder
Finally migrate the database
bash $ php artisan migrate
Migration will alter the users
table to add
- username
- mobile
- mobile_verified_at
- enable_2fa
- otp_token
- otp_expiry
- otp_channel
- status (for admin to activate/deactivate user)
Migration will add two roles defined in the roles
key of the config file.
Only the User having role config('rakshak.roles.super_user')
can access the /rakshak/settings
route to view and edit the Two Factor settings.
User having either config('rakshak.roles.super_user')
or config('rakshak.roles.authorizer')
It is recommended to install the package in a fresh Laravel application
Config
Package config file is published at config/rakshak.php
.
It allows to enable Two Factor Authentication - by default it is not enabled. It also allows to replace/modify the notification used for sending the otp and welcome message on registration.
The default notifications are published in the app/Notifications/Rakshak
directory. You may modify or replace the notifications and then replace the corresponding config key with the FQCN of your new notification.
You can use any of the Laravel Notification channels for notifications. By default the package includes Textlocal Notification Channel for sms messaging.
Usage
The package provides the option to enable Two Factor Authentication as also the level of control i.e. once an administrator enables the 2fa
module it can be applied to all users by the admin or each user can be given the option to enable 2fa
for own use.
Two Factor Authentication
Route: /rakshak/settings
is also provided for if you want to provide an easy way for other/client admins to control the Two Factor Authentication.
If you want to provide user level control for enabling/disabling Two Factor Authentication, you will need to implement:
- Route and Navigation for user to access the settings area
- Settings view to:
- enable/disable
2fa
, select channelsms
or defaultemail
- check whether mobile (number) is verified if
sms
channel is selected - Button/link to send otp for mobile (number) verification
- enable/disable
HasRakshak trait
The User.php
file - as per the config('auth.providers.users.model')
is updated to use the HasRakshak
trait. The trait provides a number of functions and roles
relation to the User
.
Adding and Retracting Ability to a Role
Assigning and Retracting Role to User
Check if the User has role
Check if the User has any of given multiple role
Check if the User has ability
Check if the User has any of given multiple abilities
Roles and Abilities
Route: /rakshak/roles
will provide a list of all existing roles
Route: /rakshak/roles/{role}/edit
will provide the edit role form
Route: /rakshak/roles/create
will provide the create new role form
Similarly the corresponding routes for Abilities are also provided for easy crud operations.
All package views are published to resources/views/vendor/rakshak
directory.
Route Middleware
A route middleware role
is registered by the package.
To protect the routes with valid opt, use the rakshak.2fa
middleware.
Once Two Factor Authentication is enabled, and rakshak.2fa
middleware is applied to any route,
it will check for a valid otp associated with the user.
Once the generated otp is sent to the user and user verifies the login with otp it will stay verified till session lifetime.
Blade Directives
If you want to check against multiple roles, there's another directive where you can check against multiple roles separated by |
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-rakshak with dependencies
doctrine/dbal Version ^2.9
guzzlehttp/guzzle Version ^6.3
illuminate/support Version 5.7.*|5.8.*|5.9.*
moontoast/math Version ^1.1
thinkstudeo/textlocal-notification-channel Version ^1.0