/** * @param array $data * @param string $method * @return $this */ protected function loadIdentity(array $data, $method) { $this->identity = new Identity(); $link = $this->getUrl(); $credentials = $this->_clientId . ':' . $this->_clientSecret; $parameters = http_build_query($data); $options = [CURLOPT_FOLLOWLOCATION => true, CURLOPT_FORBID_REUSE => true, CURLOPT_HEADER => false, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_HTTPGET => false, CURLOPT_NETRC => false, CURLOPT_POST => false, CURLOPT_PUT => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 1, CURLOPT_TIMEOUT => 5, CURLOPT_URL => $link, CURLOPT_USERPWD => $credentials, CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']]; switch ($method) { case 'post': $options[CURLOPT_POST] = true; $options[CURLOPT_POSTFIELDS] = $parameters; break; default: $options[CURLOPT_HTTPGET] = true; $options[CURLOPT_URL] = $link . '?' . $parameters; } curl_setopt_array($this->curl, $options); $source = curl_exec($this->curl); /* { "access_token": "22fe0c13e995da4a44a63a7ff549badb5d337a42bf80f17424482e35d4cca91a", "expires_at": 1382962374, "expires_in": 3600, "refresh_token": "8eb667707535655f2d9e14fc6491a59f6e06f2e73170761259907d8de186b6a1", "token_type": "bearer" } */ $identity = json_decode($source, true); $this->identity->setAccessToken($identity['access_token'])->setExpireAt($identity['expires_at'])->setExpireIn($identity['expires_in'])->setRefreshToken($identity['refresh_token'])->setTokenType($identity['token_type']); return $this; }