Download the PHP package ikechukwukalu/sanctumauthstarter without Composer
On this page you can find all versions of the php package ikechukwukalu/sanctumauthstarter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ikechukwukalu/sanctumauthstarter
More information about ikechukwukalu/sanctumauthstarter
Files in ikechukwukalu/sanctumauthstarter
Package sanctumauthstarter
Short Description Laravel sanctum auth starter
License MIT
Informations about the package sanctumauthstarter
SANCTUM AUTH STARTER
This is a very flexible and customisable laravel package (boilerplate) that utilises laravel/ui and laravel-sanctum to create Basic Authetication classes and other helpful functionalities to give you a quick start when building REST APIs using Laravel. The following functionalities are made available:
- User registration
- User login
- Auto login after registration
- Login throttling
- Login 2FA
- Social media login
- Forgot password
- Email verification
- Resend email verification
- Reset password
- Change password
- Edit user profile
- Notifications
- Welcome notification
- Email verification
- Login notification
- Password change notification
- Generate documentation
- Helper CI/CD files for GitHub
REQUIREMENTS
- PHP 8+
- Laravel 9+
STEPS TO INSTALL
php artisan ui bootstrap
npm install --save-dev laravel-echo pusher-js
- Uncomment
use Illuminate\Contracts\Auth\MustVerifyEmail;
inUser
model class - Add
two_factor
columns to thefillable
andhidden
arrays within theUser
model class. At the end theUser
should look similar to this:
GENERATE AUTH CONTROLLERS, REQUESTS, SERVICES AND ROUTES
You can run php artisan sas:setup
to generate them at once. You can also call generate them separately:
php artisan sas:controllers
php artisan sas:routes
php artisan sas:tests
PUBLISH MIGRATIONS AND CONFIG
php artisan vendor:publish --tag=sas-migrations
php artisan vendor:publish --tag=sas-config
WEBSOCKETS AND QUEUES
This package utilizes laravel beyondcode/laravel-websockets to pass access_token
to the client after authentication. First, you must setup your laravel app for broadcasts. In order to do that run the following:
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="config"
- Set
REDIS_CLIENT=predis
andBROADCAST_DRIVER=pusher
within your.env
file. - Your
laravel-echo
config should look similar to this:
You will need a queue worker for the notifications and other events.
- Set
QUEUE_CONNECTION=redis
within your.env
file. - Uncomment
App\Providers\BroadcastServiceProvider::class
inconfig\app.php
-
Your
.env
should look similar to this -
For SSL using apache. The snippet below should be placed within the
virtualhost
SSL config. - Run
php artisan config:clear
,php artisan migrate
,php artisan websockets:serve
andphp artisan queue:work
php artisan serve
npm install && npm run dev
WEBVIEW LOGINS
- Social media login
- Two-factor login
Social Media Login
Add the following to your config/services.php
file.
-
Navigate to
auth/socialite
to view a sample Google sign-up/sign-in page to view the generatedaccess_token
after sign up. Uncomment the route within theweb.php
. Below is the script that is called within the viewresources/views/vendor/sanctumauthstarter/socialite/auth.blade.php
. - After a successful authentication, this view is displayed
resources/views/vendor/sanctumauthstarter/socialite/callback.blade.php
and it contains the following script:
Two-factor Login
This package utilizes Laragear/TwoFactor to power 2fa login and beyondcode/laravel-websockets to pass access_token
to the client after authentication.
2fa authentication has been implemented for both password login and social media login.
php artisan vendor:publish --provider="Laragear\TwoFactor\TwoFactorServiceProvider"
php artisan migrate
-
Replace the form in
resources/views/vendor/two-factor/login.blade.php
with the code below: -
Call
api/create-two-factor
to create 2fa. -
Call
api/confirm-two-factor
to confirm 2fa and get recovery codes. - Call
api/disable-two-factor
to disable 2fa,api/current-recovery-codes
to retrieve current recovery codes andapi/new-recovery-codes
to generate new recovery codes which replaces the previous batch.
Two factor enabled for password login
When 2fa has been enabled and a user attempts to login, a payload would be returned that contains a user_uuid
and a twofactor_url
.
The user_uuid
is used to create a laravel-echo
channel that would listen to a laravel broadcast. Navigate to auth/twofactor/{email}/{uuid}
to view the generated access_token
after uncommenting the route within the web.php
. This view resources/views/vendor/sanctumauthstarter/twofactor/auth.blade.php
contains a sample javascript
that works it out.
Two factor enabled for social media login
When 2fa has been enabled a 2fa page will pop up over your browser.
DOCUMENTATION
To generate documentation:
composer require --dev knuckleswtf/scribe
php artisan vendor:publish --tag=scribe-config
- Change
'prefixes' => ['api/*']
to'prefixes' => ['*']
if you want to see the docs for APIs for theweb.php
as well. php artisan scribe:generate
Visit your newly generated docs:
- If you're using
static
type, find thedocs/index.html
file in yourpublic/
folder and open it in your browser. - If you're using
laravel
type, start your app (php artisan serve
), then visit/docs
.
example_languages
:
For each endpoint, an example request is shown in each of the languages specified in this array. Currently, only bash
(curl), javascript
(Fetch), php
(Guzzle) and python
(requests) are included. You can add extra languages, but you must also create the corresponding Blade view (see Adding more example languages).
Default: ["bash", "javascript"]
Please visit scribe for more details.
TESTS
It's recommended that you run the tests before you start adding your custom models and controllers.
Make sure to keep your database/factories/UserFactory.php
Class updated with your users
table so that the Tests can continue to run successfully.
Passwords
The passwords created within the database/factories/UserFactory.php
Class must match the validation below:
Running Tests
php artisan test
RECOMMENED PACKAGES
PUBLISH VIEWS
php artisan vendor:publish --tag=sas-views
PUBLISH LANG
php artisan vendor:publish --tag=sas-lang
PUBLISH LARAVEL EMAIL NOTIFICATIONS BLADE
php artisan vendor:publish --tag=laravel-notifications
PUBLISH GITHUB WORKFLOWS
php artisan vendor:publish --tag=github
LICENSE
The SAS package is an open-sourced software licensed under the MIT license.
All versions of sanctumauthstarter with dependencies
doctrine/dbal Version ^3.5
hisorange/browser-detect Version ^4.5
illuminate/auth Version ^9.0|^10.0
illuminate/bus Version ^9.0|^10.0
illuminate/broadcasting Version ^9.0|^10.0
illuminate/contracts Version ^9.0|^10.0
illuminate/database Version ^9.0|^10.0
illuminate/events Version ^9.0|^10.0
illuminate/http Version ^9.0|^10.0
illuminate/notifications Version ^9.0|^10.0
illuminate/queue Version ^9.0|^10.0
illuminate/routing Version ^9.0|^10.0
illuminate/support Version ^9.0|^10.0
illuminate/validation Version ^9.0|^10.0
illuminate/view Version ^9.0|^10.0
laravel/sanctum Version ^3.0
laravel/socialite Version ^5.5
laragear/two-factor Version ^1.2
laravel/ui Version ^4.0
nesbot/carbon Version ^2.67
php Version ^8.0
predis/predis Version ^2.1
pusher/pusher-php-server Version ^7.2
stevebauman/location Version ^6.6
symfony/console Version ^6.0
symfony/finder Version ^6.0