in php/urlinfo.php [98:154]
protected function GetCognitoCredentials() {
$this->$idProviderClient = new Aws\CognitoIdentityProvider\CognitoIdentityProviderClient([
'version' => '2016-04-18',
'region' => self::$Region,
'credentials' => false,
]);
echo "Password: ";
$this->hide_term();
$this->apiPassword = rtrim(fgets(STDIN), PHP_EOL);
$this->restore_term();
try {
$result = $this->$idProviderClient->initiateAuth([
'AuthFlow' => 'USER_PASSWORD_AUTH',
'ClientId' => self::$CognitoClientId,
'UserPoolId' => self::$CognitoUserPoolId,
'AuthParameters' => [
'USERNAME' => $this->apiUser,
'PASSWORD' => $this->apiPassword,
],
]);
$accessToken = $result->get('AuthenticationResult')['AccessToken'];
$idToken = $result->get('AuthenticationResult')['IdToken'];
//echo "Access Token: $accessToken\n";
//echo "ID Token: $idToken\n";
$idClient = new Aws\CognitoIdentity\CognitoIdentityClient([
'version' => '2014-06-30',
'region' => self::$Region,
'credentials' => false,
]);
$provider = 'cognito-idp.us-east-1.amazonaws.com/'.self::$CognitoUserPoolId;
$clientIDResponse = $idClient->getId([
'IdentityPoolId' => self::$CognitoIdentityPoolId,
'Logins' => [ $provider => $idToken ]
]);
$clientId = $clientIDResponse->get('IdentityId');
$result = $idClient->getCredentialsForIdentity([
'IdentityId' => $clientId,
'Logins' => [ $provider => $idToken ]
]);
$awsCredentials = $result->get('Credentials');
return $awsCredentials;
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
echo "Error: $errorMessage";
return $e->getMessage();
}
}