alexgithubber / santanu-lumen-mongodb-oauth
基于Lumen框架和MongoDB的OAuth API授权
此包的官方仓库似乎已消失,因此该包已被冻结。
dev-master
2019-12-09 22:07 UTC
Requires
Requires (Dev)
- jenssegers/mongodb: 3.*
- laravel/lumen-framework: 5.2.*
This package is not auto-updated.
Last update: 2023-06-06 14:53:38 UTC
README
此分叉的目的是简化向oauth服务器配置发送信息(例如token有效期)并将默认授权类型更改为'client_credentials',目前不可用'password'授权类型。
Lumen & MongoDB的OAuth库
用于在Lumen框架和MongoDB上创建可授权授权的包。
包安装
- 在您的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(); }); });
在此分叉中,您可以将服务器的配置作为数组参数发送到accessToken和refreshToken方法,例如
$app->post('access', function() use($app) {
return $app->make('oauth.routes')->accessToken(['allow_implicit' => true, 'access_lifetime' => 7200]);
});
- 在路由中,将'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