depotwarehouse / oauth2-bnet
league/oauth2-client的Battle.net提供程序
Requires
- php: >=5.5.0
- illuminate/contracts: ^5.1
- league/oauth2-client: ^1.0
Suggests
- illuminate/support: Laravel integration
This package is not auto-updated.
Last update: 2024-09-24 02:33:18 UTC
README
这是一个用于集成Battle.net身份验证与The League of Extraordinary Packages的OAuth2客户端库的包。
目前与OAuth集成,以从SC2 & WoW提取配置文件。如果Diablo玩家提交PR,我将很高兴合并更改并包容。感谢@TheJaydox提交了WoW pull请求!
安装时使用composer
composer require depotwarehouse/oauth2-bnet
用法与league的OAuth客户端相同,使用\Depotwarehouse\OAuth2\Client\Provider\SC2Provider
或\Depotwarehouse\OAuth2\Client\Provider\WowProvider
作为提供程序。例如
$provider = new \Depotwarehouse\OAuth2\Client\Provider\SC2Provider([ 'clientId' => "YOUR_CLIENT_ID", 'clientSecret' => "YOUR_CLIENT_SECRET", 'redirectUri' => "http://your-redirect-uri", 'region' => 'eu' ]);
如您所见,您可以将可选的'region'参数传递给构造函数,然后它将查询该区域。如果您省略区域参数,则默认为us
区域。
if (isset($_GET['code']) && $_GET['code']) { $token = $this->provider->getAccessToken("authorizaton_code", [ 'code' => $_GET['code'] ]); // Returns an instance of Depotwarehouse\OAuth2\Client\Entity\SC2User $user = $this->provider->getResourceOwner($token);
要了解SC2User
上可用的数据,只需检查类的公共属性,因为它们显示了所有返回的数据。
对于WoW,您可以使用\Depotwarehouse\OAuth2\Client\Provider\WowProvider
,它将返回类型为WowUser
的对象。一个WowUser
仅包含一个公共的$data
属性,该属性包含作为stdClass
的对象字符数组的数组。
以下是一个示例JSON表示,但建议您使用检查来更准确地了解您要查找的内容(也许可以发送带有您找到的属性的pull请求!)
示例输出(转换为JSON以显示)
// $user-> { "data": [ { "name": "Thejaydox", "realm": "Stormreaver", "battlegroup": "Rampage", "class": 4, "race": 10, "gender": 1, "level": 88, "achievementPoints": 16330, "thumbnail": "stormreaver\/230\/89809638-avatar.jpg", "spec": { "name": "Assassination", "role": "DPS", "backgroundImage": "bg-rogue-assassination", "icon": "ability_rogue_eviscerate", "description": "A deadly master of poisons who dispatches victims with vicious dagger strikes.", "order": 0 }, "guild": "Honnouji Academy", "guildRealm": "Stormreaver", "lastModified": 1421373438000 }, ] }
测试
在test/
中有一个用于集成测试的简单脚手架。不幸的是,由于Battle.net OAuth服务要求使用https
对所有身份验证流量进行操作(但这确实对安全性有好处!),因此使用起来相当复杂。
包括用于与oauth2-bnet.local
域一起使用的SSL证书以及私钥。只需将oauth2-bnet.local
添加到您的/etc/hosts
中,作为localhost的别名,并配置apache使用test/ssl
中的证书和密钥文件来提供test/
中的文件。
接下来编辑test/config.php
以填写从https://dev.battle.net获得的自己的客户端密钥值,然后您应该能够运行测试。如果成功,页面应将您重定向到登录页面,并将您的用户值输出到屏幕。