luchavez/passport-pgt-server
Composer 安装命令:
composer require luchavez/passport-pgt-server
包简介
Laravel Passport Password Grant Tokens Server for Laravel 8|9|10
README 文档
README
Laravel Passport is an authentication package for Laravel. It is used by a lot of Laravel apps to authenticate users before accessing any resources. Basically, it generates an access token which you can then use on every request to provide identification to the OAuth Server.
One of Laravel Passport's mostly used authentication methods is the Password Grant Tokens grant type. It is a stateless way to get access tokens and refresh tokens from the OAuth Server.
Take a look at contributing.md if you want to contribute to this project.
Installation
Via Composer
// Install the package and its dependencies $ composer require luchavez/passport-pgt-server --with-all-dependencies // Publish the config, migrate Passport tables, and run passport:install $ php artisan pgt:server:install
Setting Up
-
Run
php artisan migrateto create the Passport related tables. -
Use Passport's
Laravel\Passport\HasApiTokenson User model. -
Add these variables to
.envfile if you want to override the default values.
| Variable Name | Default Value |
|---|---|
PASSPORT_ACCESS_TOKEN_EXPIRES_IN |
15 days |
PASSPORT_REFRESH_TOKEN_EXPIRES_IN |
30 days |
PASSPORT_PERSONAL_ACCESS_TOKEN_EXPIRES_IN |
6 days |
PASSPORT_HASH_CLIENT_SECRETS |
false |
Usage
Passport PGT Server
The package provides a service called PassportPgtServer which you can use by calling its helper functions:
passportPgtServer()passport_pgt_server()
Here's the list of its available methods.
| Method Name | Return Type | Description |
|---|---|---|
setPassportAsApiDriver |
void |
adds api authentication guard with passport as driver |
setPassportEncryptionKeys |
void |
used for overriding Passport encryption keys |
hashClientSecrets |
bool |
decides whether to hash or not client's secrets |
getTokensExpiresIn |
Illuminate\Support\Carbon |
gets the Carbon datetime for access token expiration |
getRefreshTokensExpiresIn |
Illuminate\Support\Carbon |
gets the Carbon datetime for refresh token expiration |
getPersonalAccessTokensExpiresIn |
Illuminate\Support\Carbon |
gets the Carbon datetime for personal access token expiration |
getTokenModel |
string |
gets the model class name |
getTokenBuilder |
Illuminate\Database\Eloquent\Builder |
gets the model builder instance |
getRefreshTokenModel |
string |
gets the model class name |
getRefreshTokenBuilder |
Illuminate\Database\Eloquent\Builder |
gets the model builder instance |
getPersonalAccessTokenModel |
string |
gets the model class name |
getPersonalAccessTokenBuilder |
Illuminate\Database\Eloquent\Builder |
gets the model builder instance |
getClientModel |
string |
gets the model class name |
getClientBuilder |
Illuminate\Database\Eloquent\Builder |
gets the model builder instance |
Routes
By default, laravel/passport adds authentication related routes. This package adds two new routes: /api/oauth/logout and /api/oauth/me.
Here's the list of routes that this package provides.
| Method | Route | Description |
|---|---|---|
| POST | /oauth/token |
Added by laravel/passport. This route generates the tokens. |
| GET | /api/oauth/register |
This route is where we register a new user. |
| POST | /api/oauth/logout |
This route revokes the current access token with refresh token. |
| GET | /api/oauth/me |
This route returns the access token's user information. |
Note: If you wish to override the logout or get self logic, feel free to do so by updating the published passport-pgt-server config file.
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email jamescarloluchavez@gmail.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
luchavez/passport-pgt-server 适用场景与选型建议
luchavez/passport-pgt-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 250 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth2」 「laravel」 「PassportPgtServer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 luchavez/passport-pgt-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 luchavez/passport-pgt-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 luchavez/passport-pgt-server 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Email Toolkit Plugin for CakePHP
The missing social authentication for thephpleague/oauth2-server, adapted from schedula/league-oauth2-social
Alfabank REST API integration
Oauth 2 client for Ubiquity framework
Authorization Server library for OAuth 2.0 Authorization Framework
统计信息
- 总下载量: 250
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-22
