/** * Parses the access token response and returns a TokenInterface. * * * @param string $responseBody * * @return TokenInterface * * @throws TokenResponseException */ protected function parseAccessTokenResponse($responseBody) { $request = \Request::getInstance(); if ($request->get('error')) { $reason = $request->get('error_description'); throw new TokenResponseException($reason); } $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']); $token->setLifetime($data['expires_in']); if (isset($data['refresh_token'])) { $token->setRefreshToken($data['refresh_token']); unset($data['refresh_token']); } unset($data['access_token']); unset($data['expires_in']); $data['state'] = $request->get('state'); $token->setExtraParams($data); return $token; }
/** * {@inheritdoc} */ protected function parseAccessTokenResponse($responseBody) { $data = json_decode($responseBody, true); if (is_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']); $token->setLifetime(0); if (isset($data['refresh_token'])) { $token->setRefreshToken($data['refresh_token']); unset($data['refresh_token']); } unset($data['access_token']); $token->setExtraParams($data); return $token; }
/** * @param string $responseBody * @return StdOAuth2Token * @throws TokenResponseException */ protected function parseAccessTokenResponse($responseBody) { $data = $this->service->parseAccessTokenResponse($responseBody); if (!isset($data) || !is_array($data)) { throw new TokenResponseException('Unable to parse response.'); } $error = $this->service->getAccessTokenResponseError($data); if (isset($error)) { throw new TokenResponseException('Error in retrieving token: "' . $error . '"'); } $token = new StdOAuth2Token(); $names = $this->service->getAccessTokenArgumentNames(); $token->setAccessToken($data[$names['access_token']]); unset($data[$names['access_token']]); if (isset($data[$names['expires_in']])) { $token->setLifeTime($data[$names['expires_in']]); unset($data[$names['expires_in']]); } else { $token->setLifetime($this->service->getTokenDefaultLifetime()); } if (isset($data[$names['refresh_token']])) { $token->setRefreshToken($data[$names['refresh_token']]); unset($data[$names['refresh_token']]); } $token->setExtraParams($data); return $token; }