Module N Auth. Module to authenticate & authorize for Laravel
To start using the authentication package from NAuth, you need to initialize a submodule for your Laravel project.
git clone https://github.com/ChauCongTu/laravel-module-nauth.git packages/nauth_module
"scripts": {...},
"repositories": [
{
"type": "path",
"url": "packages/*"
}
],
Run that command composer require cqn/nauth_module
<?php
namespace App\Models;
...
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
...
}
Config your .env
file:
GOOGLE_CLIENT_ID="your_id"
GOOGLE_CLIENT_SECRET="your_secret_key"
GOOGLE_REDIRECT="Your_callback_url
config/app.php
'providers' => ServiceProvider::defaultProviders()->merge([
...
Spatie\Permission\PermissionServiceProvider::class,
])->toArray(),
'aliases' => Facade::defaultAliases()->merge([
...
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
])->toArray(),
config/auth.php
'guards' => [
...
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
Middleware/Authenticate.php
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : route('403');
}
}
See: Api Document