Skip to content

Commit 8693847

Browse files
committed
Merge branch 'master' of git://github.com/AJH16/php-oauth into AJH16-master
2 parents ec1bffc + 4a48738 commit 8693847

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\OAuth2\Token\StdOAuth2Token;
5+
use OAuth\Common\Http\Exception\TokenResponseException;
6+
use OAuth\Common\Http\Uri\Uri;
7+
use OAuth\Common\Consumer\Credentials;
8+
use OAuth\Common\Http\Client\ClientInterface;
9+
use OAuth\Common\Storage\TokenStorageInterface;
10+
use OAuth\Common\Http\Uri\UriInterface;
11+
12+
class BattleNetBase extends AbstractService
13+
{
14+
/**
15+
* Scopes
16+
*
17+
* @var string
18+
*/
19+
20+
const SCOPE_WOW_PROFILE = 'wow.profile';
21+
const SCOPE_SC2_PROFILE = 'sc2.profile';
22+
23+
/**
24+
* BattleNet Region
25+
*
26+
* @var string
27+
*/
28+
protected $region;
29+
30+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
31+
{
32+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
33+
if ( null === $baseApiUri ) {
34+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
35+
}
36+
}
37+
38+
/**
39+
* @return \OAuth\Common\Http\Uri\UriInterface
40+
*/
41+
public function getAuthorizationEndpoint()
42+
{
43+
return new Uri('https://' . $this->region . '.battle.net/oauth/authorize');
44+
}
45+
46+
/**
47+
* @return \OAuth\Common\Http\Uri\UriInterface
48+
*/
49+
public function getAccessTokenEndpoint()
50+
{
51+
return new Uri('https://' . $this->region . '.battle.net/oauth/token');
52+
}
53+
54+
/**
55+
* @param string $responseBody
56+
* @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
57+
* @throws \OAuth\Common\Http\Exception\TokenResponseException
58+
*/
59+
protected function parseAccessTokenResponse($responseBody)
60+
{
61+
$data = json_decode( $responseBody, true );
62+
63+
if( null === $data || !is_array($data) ) {
64+
throw new TokenResponseException('Unable to parse response.');
65+
} elseif( isset($data['error'] ) ) {
66+
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
67+
}
68+
69+
$token = new StdOAuth2Token();
70+
71+
$token->setAccessToken( $data['access_token'] );
72+
// I'm invincible!!!
73+
$token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
74+
unset( $data['access_token'] );
75+
$token->setExtraParams( $data );
76+
77+
return $token;
78+
}
79+
80+
/**
81+
* @return int
82+
*/
83+
protected function getAuthorizationMethod()
84+
{
85+
return static::AUTHORIZATION_METHOD_QUERY_STRING;
86+
}
87+
}

src/OAuth2/Service/BattleNetCN.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\Common\Http\Uri\Uri;
5+
use OAuth\Common\Consumer\Credentials;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Storage\TokenStorageInterface;
8+
use OAuth\Common\Http\Uri\UriInterface;
9+
10+
class BattleNetCN extends BattleNetBase
11+
{
12+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
13+
{
14+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
15+
$this->region = 'cn';
16+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
17+
}
18+
}

src/OAuth2/Service/BattleNetEU.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\Common\Http\Uri\Uri;
5+
use OAuth\Common\Consumer\Credentials;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Storage\TokenStorageInterface;
8+
use OAuth\Common\Http\Uri\UriInterface;
9+
10+
class BattleNetEU extends BattleNetBase
11+
{
12+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
13+
{
14+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
15+
$this->region = 'eu';
16+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
17+
}
18+
}

src/OAuth2/Service/BattleNetKR.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\Common\Http\Uri\Uri;
5+
use OAuth\Common\Consumer\Credentials;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Storage\TokenStorageInterface;
8+
use OAuth\Common\Http\Uri\UriInterface;
9+
10+
class BattleNetKR extends BattleNetBase
11+
{
12+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
13+
{
14+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
15+
$this->region = 'kr';
16+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
17+
}
18+
}

src/OAuth2/Service/BattleNetTW.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\Common\Http\Uri\Uri;
5+
use OAuth\Common\Consumer\Credentials;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Storage\TokenStorageInterface;
8+
use OAuth\Common\Http\Uri\UriInterface;
9+
10+
class BattleNetTW extends BattleNetBase
11+
{
12+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
13+
{
14+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
15+
$this->region = 'tw';
16+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
17+
}
18+
}

src/OAuth2/Service/BattleNetUS.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace OAuth\OAuth2\Service;
3+
4+
use OAuth\Common\Http\Uri\Uri;
5+
use OAuth\Common\Consumer\Credentials;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Storage\TokenStorageInterface;
8+
use OAuth\Common\Http\Uri\UriInterface;
9+
10+
class BattleNetUS extends BattleNetBase
11+
{
12+
public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
13+
{
14+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
15+
$this->region = 'us';
16+
$this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/');
17+
}
18+
}

0 commit comments

Comments
 (0)