zfr/zfr-oauth2-server-module
Composer 安装命令:
composer require zfr/zfr-oauth2-server-module
包简介
Zend Framework 2 module for ZfrOAuth2Server
README 文档
README
ZfrOAuth2Module\Server is a Zend Framework 2 module for ZfrOAuth2\Server. Its goal is to easily create a OAuth 2 compliant server.
Requirements
- PHP 5.5 or higher
- ZfrOAuth2Server
Versioning note
Please note that until I reach 1.0, I WILL NOT follow semantic version. This means that BC can occur between 0.1.x and 0.2.x releases. If you are using this in production, please set your dependency using 0.1.*, for instance.
Installation
Installation is only officially supported using Composer:
php composer.phar require zfr/zfr-oauth2-server-module:0.7.*
Copy-paste the zfr_oauth2_server.global.php.dist file to your autoload folder, and enable the module by adding
ZfrOAuth2Module\Server to your application.config.php file.
Documentation
Configuring the module
ZfrOAuth2Module\Server provides a lot of default configuration. However, there are some information you need to provide.
Setting the User class
When a token is generated, it is automatically linked to an owner. Most of the time, it will be a user. For this
mapping to work, you must make sure your user class implements the ZfrOAuth2\Server\Entity\TokenOwnerInterface
interface. Then, you need to modify the Doctrine mapping to associate this interface with your own user
class. The code is already set in the zfr_oauth2_server.global.php.dist file:
use Application\Entity\User; use ZfrOAuth2\Server\Entity\TokenOwnerInterface; return [ 'doctrine' => [ 'entity_resolver' => [ 'orm_default' => [ TokenOwnerInterface::class => Application\Entity\User::class ] ] ] ]
Adding grant types
By default, your OAuth2 server does not support anything. You must configure it by adding all the grants you want to support. For instance, the following config will make your server compatible with the "User credentials" grant as well as the "Refresh token" grant:
use ZfrOAuth2\Server\Grant\PasswordGrant; use ZfrOAuth2\Server\Grant\RefreshTokenGrant'; return [ 'zfr_oauth2_server' => [ 'grants' => [ PasswordGrant::class, RefreshTokenGrant::class ] ] ]
Specifying a callable for validating password and username
When using the "User credentials" grant (also called the Password grant), the username and password are automatically
passed to a callable. If the callable return a TokenOwnerInterface instance, then it's considered as valid and
the access token is created. Otherwise, an error is thrown.
return [ 'zfr_oauth2_server' => [ 'owner_callable' => function($username, $password) { // If valid, return the user, otherwise return null } ] ];
You can also pass a service key, that will be pulled from the service manager, if you need to inject dependencies.
Delete expired tokens
ZfrOAuth2Module\Server offers a console route you can use to delete expired access tokens. You can use this as a CRON
task to clean your database. In the public folder, use the following command:
php index.php oauth2 server delete expired tokens.
zfr/zfr-oauth2-server-module 适用场景与选型建议
zfr/zfr-oauth2-server-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36.71k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth」 「server」 「oauth 2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zfr/zfr-oauth2-server-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zfr/zfr-oauth2-server-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zfr/zfr-oauth2-server-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
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.
A jQuery augmented PHP library for creating and validating HTML forms
annotations-scan-plugin
统计信息
- 总下载量: 36.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-13