/** * Parses an access token response. * * @param Vinelab\Http\Response $response * * @return array */ public function parseResponse(Response $response) { $json = $response->json(); /* * The returned response must not be in JSON * format, unless it is an error. */ if (!is_null($json)) { if (isset($json->error)) { $error = $json->error; throw new AccessTokenException($error->type . ': ' . $error->message, $error->code); } } $token = $response->content(); return $this->parseToken($token); }
/** * Parses a response coming from Facebook * containing a profile. * * @param Vinelab\Http\Response $response * @param Vinelab\Contracts\AccessTokenInterface $access_token * * @return Vinelab\Auth\Social\Profile */ public function parseProfileResponse(Response $response, AccessTokenInterface $access_token) { $profile = $response->json(); if (gettype($profile) !== 'object') { throw new InvalidProfileException(); } if (isset($profile->error)) { $error = $profile->error; throw new InvalidProfileException($error->type . ': ' . $error->message, $error->code); } $profile->access_token = $access_token->token(); return $this->profile->instantiate($profile, $this->name); }