/** * Send a request to the OAuth endpoint. * * @param array $params * * @return AccessToken * * @throws ModomuSDKException */ protected function requestAnAccessToken(array $params) { $this->lastRequest = new ModomuRequest($this->app, $this->app->getAccessToken(), 'POST', '/oauth2/token', $params); $response = $this->client->sendRequest($this->lastRequest); $data = $response->getDecodedBody(); if (!isset($data['access_token'])) { throw new ModomuSDKException('Access token was not returned from Graph.', 401); } // Graph returns two different key names for expiration time // on the same endpoint. Doh! :/ $expiresAt = 0; if (isset($data['expires'])) { // For exchanging a short lived token with a long lived token. // The expiration time in seconds will be returned as "expires". $expiresAt = time() + $data['expires']; } elseif (isset($data['expires_in'])) { // For exchanging a code for a short lived access token. // The expiration time in seconds will be returned as "expires_in". $expiresAt = time() + $data['expires_in']; } //Si existe signature validar /*if (isset($data['signature'])) { $msj = $this->app->getId() . '|' . $data['issued_at']; if(!self::verify($msj,$data['signature'],$this->app->getSecret())){ throw new ModomuSDKException("La firma enviada por el servidor no coincide con la esperada", 1); } }*/ //Gets access_token return new AccessToken($data['access_token'], $expiresAt); }