Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function exchangeAuthorizationCodeForToken($code)
- {
- $client = new CognitoIdentityProviderClient([
- 'version' => Yii::$app->params['aws']['version'],
- 'region' => Yii::$app->params['aws']['region'],
- 'credentials' => [
- 'key' => Yii::$app->params['aws']['credentials']['key'],
- 'secret' => Yii::$app->params['aws']['credentials']['secret'],
- ]
- ]);
- try {
- $result = $client->exchangeAuthorizationCode([
- 'ClientId' => $this->client_id,
- 'ClientSecret' => Yii::$app->params['aws']['client_secret'],
- 'RedirectUri' => $this->redirect_uri,
- 'Code' => $code,
- ]);
- if (isset($result['AccessToken'])) {
- // Access token obtained, use it to retrieve user object
- $accessToken = $result['AccessToken'];
- return $accessToken;
- } else {
- // Error exchanging authorization code for access token
- echo 'Error exchanging authorization code for access token';
- }
- } catch (CognitoIdentityProviderException $e) {
- // Error exchanging authorization code for access token
- echo $e->getMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement