定制 depotwarehouse/oauth2-bnet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

depotwarehouse/oauth2-bnet

Composer 安装命令:

composer require depotwarehouse/oauth2-bnet

包简介

A Battle.net provider for league/oauth2-client

README 文档

README

This is a package to integrate Battle.net authentication with the OAuth2 client library by The League of Extraordinary Packages.

Currently integrated with OAuth to pull profiles from SC2 & WoW. If Diablo players submit a PR, I'd be happy to merge in changes and be inclusive :) Thanks to @TheJaydox for submitting a WoW pull!

To install, use composer:

composer require depotwarehouse/oauth2-bnet

Usage is the same as the league's OAuth client, using \Depotwarehouse\OAuth2\Client\Provider\SC2Provider or \Depotwarehouse\OAuth2\Client\Provider\WowProvider as the provider. For example:

$provider = new \Depotwarehouse\OAuth2\Client\Provider\SC2Provider([
    'clientId' => "YOUR_CLIENT_ID",
    'clientSecret' => "YOUR_CLIENT_SECRET",
    'redirectUri' => "http://your-redirect-uri",
    'region' => 'eu'
]);

As you can see you may pass an optional 'region' argument to the constructor, and it will then query on that region instead. If you omit the region argument, then it will default to the us region.

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);

To get to know the data available on an SC2User simply inspect the public properties of the class, as they show all the available data that has been returned.

Alternatively, for WoW you can use \Depotwarehouse\OAuth2\Client\Provider\WowProvider and it will return an object of type WowUser. A WowUser simply contains a public $data property with an array of character objects as stdClasss.

There's an example JSON representation below, but I suggest you use inspection to figure out more closely what you're looking for (and maybe send a pull request with the properties you find!)

Example output (converted to JSON for display):

// $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
    },
    ]
}

Testing

There is a simple scaffold for an integration test in test/. Unfortunately, it is nontrivial to use, as the Battle.net OAuth service requires the use of https for all authentication traffic (but that does bode well for security!)

Included is an SSL certificate as well as a private key for use with the domain oauth2-bnet.local. Simply add oauth2-bnet.local to your /etc/hosts as an alias for localhost, and configure apache to serve the files in test/ using the certificate and key files in test/ssl.

Next edit test/config.php to fill in the values for your own client key from https://dev.battle.net and you should be able to run the test. The page should redirect you to log in, and then dump your user values to screen if successful.

统计信息

  • 总下载量: 2.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 3
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固