public function testIsValidDetectsGoodResponse() { $data = array('oauth_token' => 'jZaee4GF52O3lUb9', 'foo' => 'bar'); $token = new AuthorizedRequestToken($data); $this->assertTrue($token->isValid()); }
/** * Retrieve an Access Token in exchange for a previously received/authorized * Request Token. * * @param array $queryData GET data returned in user's redirect from Provider * @param \ZendOAuth\Token\Request Request Token information * @param string $httpMethod * @param \ZendOAuth\Http\AccessToken $request * @return \ZendOAuth\Token\Access * @throws Exception\InvalidArgumentException on invalid authorization token, non-matching response authorization token, or unprovided authorization token */ public function getAccessToken($queryData, Token\Request $token, $httpMethod = null, Http\AccessToken $request = null) { $authorizedToken = new Token\AuthorizedRequest($queryData); if (!$authorizedToken->isValid()) { throw new Exception\InvalidArgumentException('Response from Service Provider is not a valid authorized request token'); } if ($request === null) { $request = new Http\AccessToken($this); } // OAuth 1.0a Verifier if ($authorizedToken->getParam('oauth_verifier') !== null) { $params = array_merge($request->getParameters(), array('oauth_verifier' => $authorizedToken->getParam('oauth_verifier'))); $request->setParameters($params); } if ($httpMethod !== null) { $request->setMethod($httpMethod); } else { $request->setMethod($this->getRequestMethod()); } if (isset($token)) { if ($authorizedToken->getToken() !== $token->getToken()) { throw new Exception\InvalidArgumentException('Authorized token from Service Provider does not match' . ' supplied Request Token details'); } } else { throw new Exception\InvalidArgumentException('Request token must be passed to method'); } $this->_requestToken = $token; $this->_accessToken = $request->execute(); return $this->_accessToken; }