protected function _parseToken($responseBody) { $data = $this->_parseResponseBody($responseBody); $token = new StdOAuth1Token(); $token->setRequestToken($data['oauth_token']); $token->setRequestTokenSecret($data['oauth_token_secret']); $token->setAccessToken($data['oauth_token']); $token->setAccessTokenSecret($data['oauth_token_secret']); $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); unset($data['oauth_token'], $data['oauth_token_secret']); $token->setExtraParams($data); return $token; }
/** * {@inheritdoc} */ protected function parseAccessTokenResponse($responseBody) { parse_str($responseBody, $data); 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 StdOAuth1Token(); $token->setRequestToken($data['oauth_token']); $token->setRequestTokenSecret($data['oauth_token_secret']); $token->setAccessToken($data['oauth_token']); $token->setAccessTokenSecret($data['oauth_token_secret']); $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); unset($data['oauth_token'], $data['oauth_token_secret']); $token->setExtraParams($data); return $token; }
/** * Create token object from array. * * @param array $data * @return TokenInterface */ public function arrayToToken(array $data) { if ($data && array_key_exists('accessToken', $data) && array_key_exists('accessTokenSecret', $data) && array_key_exists('requestToken', $data) && array_key_exists('requestTokenSecret', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) { $token = new StdOAuth1Token($data['accessToken']); $token->setAccessTokenSecret($data['accessTokenSecret']); $token->setRequestToken($data['requestToken']); $token->setRequestTokenSecret($data['requestTokenSecret']); $token->setEndOfLife($data['endOfLife']); $token->setExtraParams($data['extraParams']); } elseif ($data && array_key_exists('accessToken', $data) && array_key_exists('refreshToken', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) { $token = new StdOAuth2Token($data['accessToken'], $data['refreshToken'], null, $data['extraParams']); $token->setEndOfLife($data['endOfLife']); } if (!isset($token) || !$token) { return null; } return $token; }
/** * {@inheritdoc} */ protected function parseAccessTokenResponse($sResponseBody) { $aData = array(); parse_str($sResponseBody, $aData); if ($aData === null || !is_array($aData)) { throw new TokenResponseException('Unable to parse response.'); } else { if (isset($aData['oauth_err_code']) && isset($aData['oauth_err_message'])) { throw new TokenResponseException('Error in retrieving token: "' . $aData['oauth_err_message'] . '"'); } } $oToken = new StdOAuth1Token(); $oToken->setRequestToken($aData['oauth_token']); $oToken->setRequestTokenSecret($aData['oauth_token_secret']); $oToken->setAccessToken($aData['oauth_token']); $oToken->setAccessTokenSecret($aData['oauth_token_secret']); $oToken->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); unset($aData['oauth_token'], $aData['oauth_token_secret']); $oToken->setExtraParams($aData); return $oToken; }
/** * Get token from storage * * @param string $provider * @param int $key * @return Token */ public function getToken($provider, $key) { $provider = ucfirst(strtolower($provider)); $data = $this['option']->get('oauth:token:' . $provider . ':' . $key); if ($data && array_key_exists('accessToken', $data) && array_key_exists('accessTokenSecret', $data) && array_key_exists('requestToken', $data) && array_key_exists('requestTokenSecret', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) { $token = new StdOAuth1Token($data['accessToken']); $token->setAccessTokenSecret($data['accessTokenSecret']); $token->setRequestToken($data['requestToken']); $token->setRequestTokenSecret($data['requestTokenSecret']); $token->setEndOfLife($data['endOfLife']); $token->setExtraParams($data['extraParams']); } elseif ($data && array_key_exists('accessToken', $data) && array_key_exists('refreshToken', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) { $token = new StdOAuth2Token($data['accessToken'], $data['refreshToken'], null, $data['extraParams']); $token->setEndOfLife($data['endOfLife']); } if (!isset($token) || !$token) { return null; } return $token; }
/** * @param string|array $responseBody * @return StdOAuth1Token * @throws TokenResponseException */ protected function parseAccessTokenResponse($responseBody) { if (!is_array($responseBody)) { parse_str($responseBody, $data); if (!isset($data) || !is_array($data)) { throw new TokenResponseException('Unable to parse response.'); } } else { $data = $responseBody; } $error = $this->service->getAccessTokenResponseError($data); if (isset($error)) { throw new TokenResponseException('Error in retrieving token: "' . $error . '"'); } $token = new StdOAuth1Token(); $names = $this->service->getAccessTokenArgumentNames(); $token->setRequestToken($data[$names['oauth_token']]); $token->setRequestTokenSecret($data[$names['oauth_token_secret']]); $token->setAccessToken($data[$names['oauth_token']]); $token->setAccessTokenSecret($data[$names['oauth_token_secret']]); unset($data[$names['oauth_token']], $data[$names['oauth_token_secret']]); if (isset($data[$names['oauth_expires_in']])) { $token->setLifeTime($data[$names['oauth_expires_in']]); unset($data[$names['oauth_expires_in']]); } else { $token->setLifetime($this->service->getTokenDefaultLifetime()); } $token->setExtraParams($data); return $token; }