znerol/oauth2-server-storeauth-grant
最新稳定版本:2.0.0
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
统计信息
- 总下载量: 160
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-20