2017 © Pedro Peláez
 

library oauth2-bnet

A Battle.net provider for league/oauth2-client

image

depotwarehouse/oauth2-bnet

A Battle.net provider for league/oauth2-client

  • Sunday, April 17, 2016
  • by bonywonix
  • Repository
  • 3 Watchers
  • 17 Stars
  • 2,075 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 4 Open issues
  • 14 Versions
  • 3 % Grown

The README.md

Battle.net provider for league/oauth2-client

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

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!, (*2)

To install, use composer:, (*3)

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:, (*4)

$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., (*5)

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., (*6)

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., (*7)

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!), (*8)

Example output (converted to JSON for display):, (*9)

// $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!), (*10)

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., (*11)

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., (*12)

The Versions

17/04 2016

dev-master

9999999-dev

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

17/04 2016

5.0.2

5.0.2.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

15/01 2016

5.0.1

5.0.1.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

29/09 2015

5.0.0

5.0.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

21/08 2015

4.0

4.0.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

28/05 2015

3.0.1

3.0.1.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

20/05 2015

3.0.0

3.0.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

26/02 2015

2.0.0

2.0.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

26/02 2015

2.0.1

2.0.1.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

12/01 2015

1.1.2

1.1.2.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2014

1.1.1

1.1.1.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

27/11 2014

1.1.0

1.1.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

12/09 2014

1.0.0

1.0.0.0

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

11/09 2014

dev-add_bnet_accountId

dev-add_bnet_accountId

A Battle.net provider for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires