judasprabin / auth-manager
为Lumen/Laravel提供的Auth0包装器
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-09-23 23:57:44 UTC
README
使用PHP 8.0版本管理Lumen和Laravel在微服务中的Auth0集成。
安装
通过composer
$ composer require carsguide/auth-manager
环境设置 .env文件
AUTH0_AUDIENCE=
AUTH0_OAUTH_URL=
AUTH0_DOMAIN=
AUTH0_JWT_CLIENTID=
AUTH0_JWT_CLIENTSECRET=
AUTH0_ALGORITHM=
注册服务提供者
Lumen
将以下代码片段添加到bootstrap/app.php
文件中的服务提供者注册部分
$app->register(Carsguide\Auth\Providers\AuthManagerServiceProvider::class);
Laravel
将以下代码片段添加到config/app.php
文件中的服务提供者注册部分
Carsguide\Auth\Providers\AuthManagerServiceProvider::class,
注册中间件
要使用令牌和范围验证,通过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, ];
使用
生成JWT令牌
use Carsguide\Auth\AuthManager; use GuzzleHttp\Client; $auth = new AuthManager(new Client()); $auth = $auth->setAudience('foobar'); $auth->getToken();
使用AuthManager
外观
use Carsguide\Auth\Facades\AuthManager; AuthManager::setAudience('foobar')->getToken();
缓存JWT令牌
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();
验证JWT令牌/范围访问
每个令牌都通过中间件进行验证。您必须在路由或控制器中调用中间件以验证访问。中间件需要定义范围,不能是全局的。
$this->middleware('auth:listings:read');
使用路由文件
$router->get('admin/profile', ['middleware' => 'auth:listings:read', function () { // }]);