/** * (non-PHPdoc) * * @see \Slince\OAuth\Service\AbstractService::retrieveTokenFromResponse() */ function retrieveTokenFromResponse($body, TokenInterface $token) { parse_str($body, $data); if (!empty($data) && !isset($data['error'])) { $token->setAccessToken($data['access_token']); $token->setRefreshToken($data['refresh_token']); $token->setExpireTime(time() + $data['expires_in']); return $token; } throw new OAuthException('Error response body'); }
/** * (non-PHPdoc) * * @see \Slince\OAuth\Service\ServiceInterface::retrieveTokenFromResponse() */ function retrieveTokenFromResponse($body, TokenInterface $token) { $data = json_decode($body, true); if (json_last_error() == JSON_ERROR_NONE && !isset($data['error'])) { $token->setAccessToken($data['access_token']); $token->setRefreshToken($data['refresh_token']); $token->setExpireTime(time() + $data['expires_in']); return $token; } throw new OAuthException('Error response body'); }
/** * (non-PHPdoc) * * @see \Slince\OAuth\Service\ServiceInterface::request() */ function request($path, $params = []) { if ($this->_token->isExpired()) { throw new ExpiredTokenException(); } $requestParams = array_merge(['access_token' => $this->_token->getAccessToken()], $params); $body = RequestFactory::create($this->getFullUrl($path), $this->_buildRequestParam($requestParams, $this->getRequestMethod()), $this->getRequestMethod()); return $this->_parseResponse($body); }