Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function exchangeAuthorizationCodeForToken($code)
- {
- $token_url = $this->domain_url ."/oauth2/token";
- $params = array(
- 'grant_type' => 'authorization_code',
- 'client_id' => $this->client_id,
- 'code' => $code,
- 'redirect_uri' => $this->redirect_uri,
- );
- $headers = [];
- $headers[] = 'Content-Type: application/x-www-form-urlencoded';
- $headers[] = 'Authorization: Basic ' . base64_encode($this->client_id . ':' . Yii::$app->params['aws']['client_secret']);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $token_url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($ch);
- curl_close($ch);
- return json_decode($response, true);
- }
Add Comment
Please, Sign In to add comment