judasprabin / auth-manager
Auth0 wrapper for Lumen/Laravel
v10.0
2024-01-23 01:44 UTC
Requires
- php: ^8.1
- auth0/auth0-php: 8.4.0
- einar-hansen/laravel-psr-6-cache: ^1.0
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.2
- illuminate/cache: ^10.0
- illuminate/container: ^10.0
- illuminate/http: ^10.0
- illuminate/log: ^10.0
- illuminate/support: ^10.0
- psr/cache: ^3.0
- symfony/cache: ^6.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^5.0
- dev-master
- v10.0
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- v8.0.0
- v6.0.0
- v5.1.0
- v5.0.0
- v4.0.0
- v3.0.0
- v2.0.1
- v2.0.0
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-feature/MCT-242
- dev-feature-cacheitempool-fix
- dev-feature-lock-auth0
- dev-feature/firebase-update
- dev-feature/firebase-update-7.4
- dev-feature-laravel-9
- dev-feature-lumen-9
- dev-ev-9d9
- dev-feature/update_dependencies
- dev-feature-lumen-8
- dev-feature-lumen-7
- dev-exception-error-auth0
- dev-CacheTime
This package is auto-updated.
Last update: 2024-12-24 00:27:46 UTC
README
Manages Lumen and Laravel Auth0 integration in microservices using PHP 8.0 version.
Installation
Via composer
$ composer require carsguide/auth-manager
Environment settings .env file
AUTH0_AUDIENCE=
AUTH0_OAUTH_URL=
AUTH0_DOMAIN=
AUTH0_JWT_CLIENTID=
AUTH0_JWT_CLIENTSECRET=
AUTH0_ALGORITHM=
Registering service provider
Lumen
Add the following snippet to the bootstrap/app.php
file under the register service providers section:
$app->register(Carsguide\Auth\Providers\AuthManagerServiceProvider::class);
Laravel
Add the following snippet to the config/app.php
file under the register service providers section:
Carsguide\Auth\Providers\AuthManagerServiceProvider::class,
Registering middleware
To use token and scope validation register the middleware via routeMiddleware()
Lumen: bootstrap/app.php
$app->routeMiddleware([ 'auth' => Carsguide\Auth\Middlewares\Auth0Middleware::class, ]);
Laravel: app/Http/kernel.php
protected $routeMiddleware = [ 'auth' => \Carsguide\Auth\Middlewares\Auth0Middleware::class, ];
Usage
Generate JWT Token
use Carsguide\Auth\AuthManager; use GuzzleHttp\Client; $auth = new AuthManager(new Client()); $auth = $auth->setAudience('foobar'); $auth->getToken();
Using AuthManager
Facade:
use Carsguide\Auth\Facades\AuthManager; AuthManager::setAudience('foobar')->getToken();
Cache JWT token:
AuthManager::setAudience('foobar') // By default, JWT will cache for 50 minutes // If you need to override the default length, // pass minutes in cache(120) method. ->cache() // or ->cache($minutes = 120) ->getToken();
Validate JWT Token / Scope Access
Each token is validated via middleware. You must call the middleware in routes or the controller to validate access. The middleware requires a scope be defined, nothing can be global.
$this->middleware('auth:listings:read');
Using routes file
$router->get('admin/profile', ['middleware' => 'auth:listings:read', function () { // }]);