baseApiUri = new Uri( self::API_URI_US ); } } /** ----------------------------------------------------------------------- * Translates the current base API URI into an OAuth base URI. * * @returns string Base URI of oauth services. */ private function GetOAuthBaseUri() { // i love china switch( $this->baseApiUri ) { case self::API_URI_US: return 'https://us.battle.net/oauth/'; case self::API_URI_EU: return 'https://eu.battle.net/oauth/'; case self::API_URI_KR: return 'https://kr.battle.net/oauth/'; case self::API_URI_TW: return 'https://tw.battle.net/oauth/'; case self::API_URI_CN: return 'https://www.battlenet.com.cn/oauth/'; case self::API_URI_SEA: return 'https://sea.battle.net/oauth/'; } } /** ----------------------------------------------------------------------- * {@inheritdoc} */ public function getAuthorizationEndpoint() { return new Uri( $this->GetOAuthBaseUri() . 'authorize' ); } /** ----------------------------------------------------------------------- * {@inheritdoc} */ public function getAccessTokenEndpoint() { return new Uri( $this->GetOAuthBaseUri() . 'token' ); } /** ----------------------------------------------------------------------- * {@inheritdoc} */ protected function getAuthorizationMethod() { return static::AUTHORIZATION_METHOD_QUERY_STRING; } /** ----------------------------------------------------------------------- * {@inheritdoc} */ protected function parseAccessTokenResponse( $responseBody ) { $data = json_decode($responseBody, true); if( $data === null || !is_array($data) ) { throw new TokenResponseException( 'Unable to parse response.' ); } elseif( isset($data['error']) ) { $err = $data['error']; throw new TokenResponseException( "Error in retrieving token: \"$err\"" ); } $token = new StdOAuth2Token( $data['access_token'], null, $data['expires_in'] ); unset( $data['access_token'] ); unset( $data['expires_in'] ); $token->setExtraParams( $data ); return $token; } }