znerol/oauth2-server-storeauth-grant
Composer 安装命令:
composer require znerol/oauth2-server-storeauth-grant
包简介
Google Billing / Apple StoreKit OAuth2 Grant Extension for PHP OAuth 2.0 Server
README 文档
README
An OAuth 2 extension grant which validates a Google Billing purchase or an Apple StoreKit transaction and returns an access token restricted to the specified SKU/product.
Dependencies
Some PSR-18 HTTP client.
Flow (Android Billing)
The client sends a POST request with following body parameters to the authorization server:
grant_typewith the valueurn:uuid:ea31e77f-cb72-486f-b5c4-deef43e839f3client_idwith the client’s IDscopewith a space-delimited list of requested scope permissionspurchase_tokenwith the android billing purchase token
The authorization server will respond with a JSON object containing the following properties:
token_typewith the valueBearerexpires_inwith an integer representing the TTL of the access tokenaccess_tokena JWT signed with the authorization server’s private key
Flow (Apple StoreKit)
The client sends a POST request with following body parameters to the authorization server:
grant_typewith the value:urn:uuid:c7e545a5-d72b-4294-a173-bb1858aae099client_idwith the client’s IDscopewith a space-delimited list of requested scope permissionstransaction_idwith the StoreKit transaction id
The authorization server will respond with a JSON object containing the following properties:
token_typewith the valueBearerexpires_inwith an integer representing the TTL of the access tokenaccess_tokena JWT signed with the authorization server’s private key
Setup
Wherever you initialize your objects, initialize a new instance of the authorization server and bind the storage interfaces and authorization code grant:
// Init our repositories $clientRepository = new ClientRepository(); // instance of ClientRepositoryInterface $scopeRepository = new ScopeRepository(); // instance of ScopeRepositoryInterface $accessTokenRepository = new AccessTokenRepository(); // instance of AccessTokenRepositoryInterface // Path to public and private keys $privateKey = 'file://path/to/private.key'; //$privateKey = new CryptKey('file://path/to/private.key', 'passphrase'); // if private key has a pass phrase $encryptionKey = 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen'; // generate using base64_encode(random_bytes(32)) // Setup the authorization server $server = new \League\OAuth2\Server\AuthorizationServer( $clientRepository, $accessTokenRepository, $scopeRepository, $privateKey, $encryptionKey );
For google non-consumables:
// Init non-consumable product repository $productRepository = ProductRepository() // instance of NonConsumableRepositoryInterface // Init google client factory $googleClientFactory = GoogleClientFactory() // instance of GoogleProductPurchaseFactoryInterface // Enable the Android purchases product grant on the server $packageName = 'com.some.thing'; $clientCredentials = // path to google api service account client credentials $server->enableGrantType( new \StoreAuth\OAuth2\Server\Grant\GoogleNonConsumable($productRepository, $googleClientFactory), new \DateInterval('PT1H') // access tokens will expire after 1 hour );
For apple non-consumables:
// Init non-consumable product repository $productRepository = ProductRepository() // instance of NonConsumableRepositoryInterface // Init apple client factory $appleClientFactory = AppleClientFactory() // instance of AppleMostRecentTransactionFactoryInterface // Enable the Apple transactions grant on the server $server->enableGrantType( new \StoreAuth\OAuth2\Server\Grant\AppleNonConsumable($productRepository, $appleClientFactory), new \DateInterval('PT1H') // access tokens will expire after 1 hour );
License
znerol/oauth2-server-storeauth-grant 适用场景与选型建议
znerol/oauth2-server-storeauth-grant 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 160 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 znerol/oauth2-server-storeauth-grant 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 znerol/oauth2-server-storeauth-grant 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 160
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-20