1. Go to this page and download the library: Download dvsa/authentication-cognito library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dvsa / authentication-cognito example snippets
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;
use Aws\Credentials\Credentials;
use Dvsa\Authentication\Cognito\Client;
# Variables below must be replaced by their respective values.
$accessKey = 'AWS_ACCESS_KEY';
$secret = 'AWS_SECRET';
$clientId = 'CLIENT_ID';
$clientSecret = 'CLIENT_SECRET';
$poolId = 'POOL_ID';
# https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Credentials.Credentials.html#___construct
$awsCredentials = new Credentials($accessKey, $secret);
# https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#___construct
$awsClient = new CognitoIdentityProviderClient([
'credentials' => $awsCredentials,
'version' => '2016-04-18',
'region' => 'eu-west-2'
]);
return new Client(
$awsClient,
$clientId,
$clientSecret,
$poolId
);
$client = new Client(
$awsClient,
$clientId,
$clientSecret,
$poolId,
$cachePool # any Psr\Cache\CacheItemPoolInterface
);
$client->setCacheOptions(
expiresAfter: 3600, # seconds. null defers to the pool's own default lifetime
rateLimit: true # cap JWKS re-fetches at 10 per minute
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.