1. Go to this page and download the library: Download gpht/oidc 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/ */
gpht / oidc example snippets
declare(strict_types=1);
use Gpht\Oidc\Client\OidcClientToken;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpClient\HttpClient;
// Create HTTP client
$httpClient = HttpClient::create();
// Create PSR-6 cache (n',
cognitoClientId: 'your-client-id',
cognitoClientSecret: 'your-client-secret'
);
// Get access token with default scopes (m2m/read, m2m/write)
// Token will be cached automatically with expiration handling
$token = $oidcClientToken->clientCredentialToken();
// Get access token with custom scopes
$token = $oidcClientToken->clientCredentialToken(['custom/read', 'custom/write']);
declare(strict_types=1);
use Gpht\Oidc\Client\OidcClientToken;
use Gpht\Oidc\Symfony\OidcUserProvider;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Contracts\HttpClient\HttpClientInterface;
return static function (ContainerConfigurator $containerConfigurator): void {
$s = $containerConfigurator->services();
$s
->defaults()
->autowire()
->autoconfigure();
// Configure OIDC Client Token service
$s
->set(OidcClientToken::class)
->arg('$cache', service('cache.app')) // Use Symfony's cache service
->arg('$tokenEndpoint', '%env(COGNITO_TOKEN_ENDPOINT)%')
->arg('$cognitoClientId', '%env(COGNITO_CLIENT_ID)%')
->arg('$cognitoClientSecret', '%env(COGNITO_CLIENT_SECRET)%');
// Configure OIDC User Provider service
$s
->set(OidcUserProvider::class);
};