santanu / lumen-mysql-oauth
基于Lumen框架和MySQL的OAuth API授权
dev-master
2017-09-18 14:26 UTC
Requires
Requires (Dev)
- laravel/lumen-framework: 5.2.*
This package is not auto-updated.
Last update: 2024-09-18 21:25:11 UTC
README
用于基于Lumen框架和MySQL创建可OAuth授权的包。
包安装
- 在您的Lumen项目中添加 "santanu/lumen-mysql-oauth": "*", 然后运行 composer update。
- 将所有迁移文件从 database/migrations 复制到项目的 db 迁移目录。
- 从项目的根目录运行 php artisan migrate。
- 在客户端集合中添加 'client_id' 和 'client_secret' 的值。
- 需要从 src/config 复制配置文件到项目的配置目录。
- 现在在 oauth.php 配置文件中更改 User 模型名称和路径。
配置应用程序
- 模型 User 应实现 Santanu\Lumen_Oauth\Interfaces\Oauthable
- 为模型 User 添加 trait Santanu\Lumen_Oauth\Traits\Oauthable
- 添加服务提供者 Santanu\Lumen_Oauth\Providers\ServiceProvider
- 在 routes/web.php 中添加以下行以添加 OAuth 服务,
$app->group(['prefix' => 'oauth'], function() use ($app) { $app->post('access', function() use($app) { return $app->make('oauth.routes')->accessToken(); }); $app->post('refresh', function() use($app) { return $app->make('oauth.routes')->refreshToken(); }); });
- 在路由中,将 'oauth' 添加为服务路由的中间件。
授权服务
- POST application-url/oauth/access 参数:grant_type(password), client_id, client_secret, username, password 响应:access_token, expires_in, token_type, scope, refresh_token
- POST application-url/oauth/refresh 参数:grant_type(refresh_token), client_id, client_secret, refresh-token 响应:access_token, expires_in, token_type, scope, refresh_token
- 在所有API请求中发送头:Authorization: Bearer access_token
重要信息
- 此库基于Lumen和MySQL,如果您正在寻找Lumen和MongoDB的包,请使用它 From: https://github.com/santanu-brahma/lumen-mongodb-oauth