/** * @param string $state * @param null|string $redirectUrl * @return Objects\Auth * @throws BuddySDKException */ public function getAccessToken($state, $redirectUrl = null) { if (empty($_GET['state']) || $_GET['state'] != $state) { throw new BuddySDKException('State does not match'); } if (empty($_GET['code'])) { throw new BuddySDKException('No code provided'); } if (empty($this->options['clientId'])) { throw new BuddySDKException('Please provide clientId'); } if (empty($this->options['clientSecret'])) { throw new BuddySDKException('Please provide clientSecret'); } $params = ['code' => $_GET['code'], 'client_id' => $this->options['clientId'], 'client_secret' => $this->options['clientSecret'], 'grant_type' => 'authorization_code']; if (isset($redirectUrl)) { $params['redirect_uri'] = $redirectUrl; } return $this->client->post($this->client->createUrl('/oauth2/token'), $params)->getAsAuth(); }
/** * @param string $accessToken * @param array $putData * @param string $url * @param array $params * @param array $query * @param string $path * @return \Buddy\BuddyResponse * @throws BuddySDKException */ protected function putJson($accessToken, array $putData, $url, array $params = [], array $query = [], $path = '/') { return $this->client->putJson($this->getAccessToken($accessToken), $this->client->createUrl($url, $params, $query, $path), $putData); }