sympla/mesa-gold-bar
最新稳定版本:3.2.5
Composer 安装命令:
composer require sympla/mesa-gold-bar
包简介
A library that provides remote user identification from oauth2 access tokens.
README 文档
README
Mesa Gold is a resort and bar located within the Westworld Mesa Hub. It is used by the Guests to relax at the end of their visit to the Park.
This library helps identifying users by their access tokens.
Installation
Install the package using composer:
$ composer require sympla/mesa-gold-bar ~3.0
That's it.
Usage
The authenticator gets two parameters in its constructor: a Guzzle client and an authentication endpoint, as a string. Once built, you can identify an user using either the raw token or a PSR-7 request object:
<?php require_once "vendor/autoload.php"; use Sympla\Auth\OAuth2RemoteAuthentication; $authenticator = new OAuth2RemoteAuthentication( new GuzzleHttp\Client, 'https://example.com/api/whoami' ); //Gets the user from the request object $request = Request::createFromGlobals(); // hydrates the psr-7 request object $user = $authenticator->getUserFromRequest($request); // Or, alternatively, gets the user from the token directly: $token = explode(" ", $_SERVER['HTTP_AUTHORIZATION'])[1]; $user = $authenticator->getUserFromToken($token); var_dump($user); // dumps information fetched from the endpoint server about the user.
Middleware
This library now also has a SlimMiddleware for retrieving user credentials.
Just add the middleware:
<?php #middleware.php $app->add(new \Sympla\Auth\Middleware\SlimMiddleware( new \GuzzleHttp\Client, $app->getContainer(), [ 'protected' => ['/^\/admin\//'], //This is a regex for the protected URIs 'authentication_server' => getenv('USER_INFO_ENDPOINT') //This is where the middleware //should try to fetch the user info from ] ));
Then, from any of the protected routes, you can simply fetch the user object
from your DIC:
<?php #routes.php $app->get('/admin', function ($request, $response, $args) { $user = $this->get('user'); var_dump($user); });
Using with Laravel
After install it, register the service provider into your Laravel application
into config/app.php:
Sympla\Auth\Laravel\ServiceProvider::class
Then, publish the configuration:
$ php artisan vendor:publish --provider="Sympla\Auth\Laravel\ServiceProvider"
Once your application is configured, go to config/auth.php and change the guard section:
'guards' => [
'api' => [
'driver' => 'token',
'provider' => 'oauth',
],
],
And the providers section:
'providers' => [
'oauth' => [
'driver' => 'oauth'
'model' => App\User::class,
],
],
Then, activate the auth:api as a middleware for your api.
Using with Lumen
After install it, register the service provider, route middleware, Hash facade and enable eloquent into your Lumen application
into bootstrap/app.php:
//Service provider
$app->register(Sympla\Auth\Lumen\ServiceProvider::class);
// Route middleware
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
//Hash facade
$app->withFacades(true, ['Illuminate\Support\Facades\Hash' => 'Hash']);
//Enable eloquent
$app->withEloquent();
After register the service provider, install the package for publish in Lumen application
$ composer require laravelista/lumen-vendor-publish
Then, publish the configuration:
$ php artisan vendor:publish --provider="Sympla\Auth\Lumen\ServiceProvider"
Once your application is configured, go to config/auth.php, if the file does not exist just create it, and change/create the guard section:
'guards' => [
'api' => [
'driver' => 'token',
'provider' => 'oauth',
],
],
And the providers section:
'providers' => [
'oauth' => [
'driver' => 'oauth'
'model' => App\User::class,
],
],
Contact
Pedro Igor pedro.igor@sympla.com.br
License
This project is distributed under the MIT License. Check [LICENSE][LICENSE.md] for more information.
sympla/mesa-gold-bar 适用场景与选型建议
sympla/mesa-gold-bar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.51k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sympla/mesa-gold-bar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sympla/mesa-gold-bar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-08