tsdarky / 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-23 07:18:02 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 request!)
示例输出(转换为 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 进行所有身份验证流量(但这确实对安全性有利!)
包含一个 SSL 证书以及用于 oauth2-bnet.local 域的私钥。只需将 oauth2-bnet.local 添加到您的 /etc/hosts 中,作为 localhost 的别名,并配置 apache 使用 test/ 中的文件,并使用 test/ssl 中的证书和密钥文件。
接下来编辑 test/config.php,填写从 https://dev.battle.net 获取的您自己的客户端密钥值,然后您应该能够运行测试。页面应将您重定向到登录页面,如果成功,则将您的用户值输出到屏幕上。