diff --git a/src/OAuth2/Service/BattleNetBase.php b/src/OAuth2/Service/BattleNetBase.php new file mode 100644 index 0000000..4868ee7 --- /dev/null +++ b/src/OAuth2/Service/BattleNetBase.php @@ -0,0 +1,87 @@ +baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } + } + + /** + * @return \OAuth\Common\Http\Uri\UriInterface + */ + public function getAuthorizationEndpoint() + { + return new Uri('https://' . $this->region . '.battle.net/oauth/authorize'); + } + + /** + * @return \OAuth\Common\Http\Uri\UriInterface + */ + public function getAccessTokenEndpoint() + { + return new Uri('https://' . $this->region . '.battle.net/oauth/token'); + } + + /** + * @param string $responseBody + * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token + * @throws \OAuth\Common\Http\Exception\TokenResponseException + */ + protected function parseAccessTokenResponse($responseBody) + { + $data = json_decode( $responseBody, true ); + + if( null === $data || !is_array($data) ) { + throw new TokenResponseException('Unable to parse response.'); + } elseif( isset($data['error'] ) ) { + throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); + } + + $token = new StdOAuth2Token(); + + $token->setAccessToken( $data['access_token'] ); + // I'm invincible!!! + $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES); + unset( $data['access_token'] ); + $token->setExtraParams( $data ); + + return $token; + } + + /** + * @return int + */ + protected function getAuthorizationMethod() + { + return static::AUTHORIZATION_METHOD_QUERY_STRING; + } +} \ No newline at end of file diff --git a/src/OAuth2/Service/BattleNetCN.php b/src/OAuth2/Service/BattleNetCN.php new file mode 100644 index 0000000..872280c --- /dev/null +++ b/src/OAuth2/Service/BattleNetCN.php @@ -0,0 +1,18 @@ +region = 'cn'; + $this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } +} \ No newline at end of file diff --git a/src/OAuth2/Service/BattleNetEU.php b/src/OAuth2/Service/BattleNetEU.php new file mode 100644 index 0000000..a304577 --- /dev/null +++ b/src/OAuth2/Service/BattleNetEU.php @@ -0,0 +1,18 @@ +region = 'eu'; + $this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } +} \ No newline at end of file diff --git a/src/OAuth2/Service/BattleNetKR.php b/src/OAuth2/Service/BattleNetKR.php new file mode 100644 index 0000000..b73aaee --- /dev/null +++ b/src/OAuth2/Service/BattleNetKR.php @@ -0,0 +1,18 @@ +region = 'kr'; + $this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } +} \ No newline at end of file diff --git a/src/OAuth2/Service/BattleNetTW.php b/src/OAuth2/Service/BattleNetTW.php new file mode 100644 index 0000000..30181cb --- /dev/null +++ b/src/OAuth2/Service/BattleNetTW.php @@ -0,0 +1,18 @@ +region = 'tw'; + $this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } +} diff --git a/src/OAuth2/Service/BattleNetUS.php b/src/OAuth2/Service/BattleNetUS.php new file mode 100644 index 0000000..4347cdc --- /dev/null +++ b/src/OAuth2/Service/BattleNetUS.php @@ -0,0 +1,18 @@ +region = 'us'; + $this->baseApiUri = new Uri('https://' . $this->region . '.api.battle.net/'); + } +} \ No newline at end of file