1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class BattleNet |
4
|
|
|
* |
5
|
|
|
* @link https://develop.battle.net/documentation |
6
|
|
|
* |
7
|
|
|
* @filesource BattleNet.php |
8
|
|
|
* @created 02.08.2019 |
9
|
|
|
* @package chillerlan\OAuth\Providers\BattleNet |
10
|
|
|
* @author smiley <[email protected]> |
11
|
|
|
* @copyright 2019 smiley |
12
|
|
|
* @license MIT |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace chillerlan\OAuth\Providers\BattleNet; |
16
|
|
|
|
17
|
|
|
use chillerlan\OAuth\Storage\OAuthStorageInterface; |
18
|
|
|
use chillerlan\Settings\SettingsContainerInterface; |
19
|
|
|
use chillerlan\OAuth\Core\{ClientCredentials, CSRFToken, OAuth2Provider, ProviderException, TokenExpires}; |
20
|
|
|
use Psr\Http\Client\ClientInterface; |
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @method \Psr\Http\Message\ResponseInterface userinfo(array $params = ['access_token']) |
25
|
|
|
*/ |
26
|
|
|
class BattleNet extends OAuth2Provider implements ClientCredentials, CSRFToken, TokenExpires{ |
27
|
|
|
|
28
|
|
|
public const SCOPE_OPENID = 'openid'; |
29
|
|
|
public const SCOPE_PROFILE_D3 = 'd3.profile'; |
30
|
|
|
public const SCOPE_PROFILE_SC2 = 'sc2.profile'; |
31
|
|
|
public const SCOPE_PROFILE_WOW = 'wow.profile'; |
32
|
|
|
|
33
|
|
|
protected $apiDocs = 'https://develop.battle.net/documentation'; |
34
|
|
|
protected $applicationURL = 'https://develop.battle.net/access/clients'; |
35
|
|
|
protected $userRevokeURL = 'https://account.blizzard.com/connections'; |
36
|
|
|
protected $endpointMap = BattleNetEndpoints::class; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* BattleNet constructor. |
40
|
|
|
* |
41
|
|
|
* @param \Psr\Http\Client\ClientInterface $http |
42
|
|
|
* @param \chillerlan\OAuth\Storage\OAuthStorageInterface $storage |
43
|
|
|
* @param \chillerlan\Settings\SettingsContainerInterface $options |
44
|
|
|
* @param \Psr\Log\LoggerInterface|null $logger |
45
|
|
|
*/ |
46
|
|
|
public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
47
|
|
|
parent::__construct($http, $storage, $options, $logger); |
48
|
|
|
|
49
|
|
|
$this->setRegion('eu'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $region |
54
|
|
|
* |
55
|
|
|
* @return \chillerlan\OAuth\Providers\BattleNet\BattleNet |
56
|
|
|
* @throws \chillerlan\OAuth\Core\ProviderException |
57
|
|
|
*/ |
58
|
|
|
public function setRegion(string $region):BattleNet{ |
59
|
|
|
$region = \strtolower($region); |
60
|
|
|
|
61
|
|
|
if(!\in_array($region, ['apac', 'cn', 'eu', 'us'], true)){ |
62
|
|
|
throw new ProviderException('invalid region: '.$region); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$url = 'https://'.($region === 'cn' ? 'www.battlenet.com.cn' : $region.'.battle.net'); |
66
|
|
|
|
67
|
|
|
$this->apiURL = $url; |
68
|
|
|
$this->authURL = $url.'/oauth/authorize'; |
69
|
|
|
$this->accessTokenURL = $url.'/oauth/token'; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|