憨图那 / lumen-mongodb-oauth
基于 Lumen 框架和 MongoDB 的 OAuth API 授权
dev-master
2017-09-18 13:40 UTC
Requires
Requires (Dev)
- jenssegers/mongodb: 3.*
- laravel/lumen-framework: 5.2.*
This package is not auto-updated.
Last update: 2024-09-24 23:34:38 UTC
README
用于在 Lumen 框架和 MongoDB 基础上创建可 OAuth 授权的包。
包安装
- 在你的 Lumen 项目中添加 "santanu/lumen-mongodb-oauth": "*",然后运行 composer update。
- 将数据库/migrations 中的所有迁移文件复制到项目的 db 迁移目录。
- 从项目的根目录运行 php artisan migrate。
- 在 clients 集合中添加 'client_id' 和 'client_secret' 值。
- 需要将 src/config 中的配置文件复制到项目的配置目录。
- 现在更改 oauth.php 配置文件中的 User 模型名称和路径。
配置应用程序
- 模型 User 应实现 Santanu\Lumen_Oauth\Interfaces\Oauthable 接口
- 为模型 User 添加 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 和 MongoDB,如果你正在寻找 Lumen 和 MySQL 包,请使用它 From: https://github.com/santanu-brahma/lumen-mysql-oauth