flownative/oauth2-client
Composer 安装命令:
composer require flownative/oauth2-client
包简介
A generic OAuth2 client base implementation for Flow Framework applications
README 文档
README
OAuth 2.0 Client for Flow Framework
This Flow package provides an OAuth 2.0 client SDK. Even though it can be used as a generic OAuth2 client, it was developed as a backing library for the OpenID Connect package. That's why documentation for this package is a bit sparse at the moment and examples for generic use are missing.
Authorizations
This package stores states and tokens as "authorizations" in a dedicated database table.
For example, during the authorization code flow, this package needs to keep track of a "state" in order to make sense of an incoming "finish authorization" request. Another example is the client credentials flow, where an access token is stored in the authorizations table which is needed for executing authorized requests to the respective service.
Token lifetime
New Authorization tokens are created with a lifetime of 600 seconds
(10 minutes) by default.
The expiration date is updated during authentication if a different
expires parameter is specified in the OAuth2 access token.
The default token lifetime and frequency of expired tokens to be removed automatically can be configured:
Flownative: OAuth2: Client: garbageCollection: # The probability in percent of a client shutdown triggering a garbage # collection which removes expired tokens. # # Examples: # 1 (would be a 1% chance to clean up) # 20 (would be a 20% chance to clean up) # 0.42 (would be a 0.42 % chance to clean up) probability: 1 token: # default lifetime of new tokens in seconds defaultLifetime: 600
Note: By setting the defaultLifetime to null, new tokens won't expire
by default.
Authorization metadata
Authorizations also may contain developer-provided metadata. For example, you may attach an account identifier to an authorization when an authorization process starts and use that information when authorization finishes to make sure that the authorization is only used for a specific account (or customer number, or participant id).
To set metadata, you need to know the authorization id when starting the
authorization code flow. This code could be used in an overloaded
startAuthorizationAction():
$authorizationId = $oAuthClient->generateAuthorizationIdForAuthorizationCodeGrant($this->appId); $loginUri = $oAuthClient->startAuthorizationWithId( $authorizationId, $this->appId, $this->appSecret, $returnToUri, $scope ); $oAuthClient->setAuthorizationMetadata($authorizationId, json_encode($metadata));
And later, in finishAuthorization(), you may retrieve the metadata as
follows:
$authorization = $this->getAuthorization($authorizationId); $metadata = json_decode($authorization->getMetadata());
Encryption
By default, access tokens are serialized and stored unencrypted in the "authorizations" database table. You can improve the security of your application by enabling the encrypted-at-rest feature of this package. when active, it will encrypt tokens before storing them in the database and decrypt them automatically when they are retrieved. The secret key which is needed for encryption and decryption is not stored in the database.
This package uses the "ChaCha20-Poly1305-IETF" construction for authenticated encryption / decryption of serialized tokens. It uses the "sodium" PHP extension if installed, or a polyfill implementation in pure PHP.
Generating a Secret Key
The OAuth2 Flow package provides a CLI command for generating encryption keys suitable for the currently supported encryption method:
$ ./flow oauth:generateencryptionkey qpBzrH7icQqBKenvk8wTKROv4qcJNxslzdGo3IKXmws=
The key is base64-encoded in order to simplify handling and being able to pass the key via Flow settings.
Enabling Encryption
Set the encryption key via Flow settings (for example in your global "Configuration/Settings.yaml"). Make sure to deploy this setting securely, for example by creating the Settings file during deployment or by using environment variables.
Flownative: OAuth2: Client: encryption: base64EncodedKey: 'qpBzrH7icQqBKenvk8wTKROv4qcJNxslzdGo3IKXmws='
Verifying Encryption Configuration
When you have set the encryption key, test that everything is working as
expected. Run your application so that a new authorization is created.
Check the database table flownative_oauth2_client_authorization: the
column serializedaccesstoken should be empty and the column
encryptedserializedaccesstoken should contain a long string similar to
his one:
ChaCha20-Poly1305-IETF$Mjdj4s9IFrPp6HFK$k9v3x…KQ==
There are three parts in this string, separated by two dollar signs:
- the construction used for encryption ("ChaCha20-Poly1305-IETF")
- the nonce used for this particular entry ("Mjdj4s9IFrPp6HFK")
- the encrypted data ("k9v3x…KQ==")
flownative/oauth2-client 适用场景与选型建议
flownative/oauth2-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112.27k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 flownative/oauth2-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flownative/oauth2-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 112.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 17
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-20