1. Go to this page and download the library: Download facile-it/php-jose-verifier 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/ */
facile-it / php-jose-verifier example snippets
// Fetched issuer metadata:
$issuerMetadata = [
'issuer' => 'https://issuer-name', // The Issuer name
'jwks_uri' => 'https://jwks_uri', // The Issuer's JWK Set URI
];
use Facile\JoseVerifier\Builder\AccessTokenVerifierBuilder;
use Facile\JoseVerifier\Exception\InvalidTokenExceptionInterface;
$builder = AccessTokenVerifierBuilder::create($issuerMetadata, $clientMetadata);
$verifier = $builder->build();
try {
$payload = $verifier->verify($jwt);
} catch (InvalidTokenExceptionInterface $e) {
// your logic here
}
use Facile\JoseVerifier\Builder\AccessTokenVerifierBuilder;use Facile\JoseVerifier\JWK\JwksProviderBuilder;
// Use your PSR SimpleCache implementation
$cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
$jwksProviderBuilder = (new JwksProviderBuilder())
->withCache($cache)
->withCacheTtl(86400); // 86400 is the default value
$builder = AccessTokenVerifierBuilder::create($issuerMetadata, $clientMetadata)
->withJwksProviderBuilder($jwksProviderBuilder);
$verifier = $builder->build();
try {
$payload = $verifier->verify($jwt);
} catch (InvalidTokenExceptionInterface $e) {
// your logic here
}
use Facile\JoseVerifier\Builder\AccessTokenVerifierBuilder;
$builder = AccessTokenVerifierBuilder::create($issuerMetadata, $clientMetadata);
$verifier = $builder->build();
try {
$payload = $verifier->verify($jwt);
} catch (InvalidTokenExceptionInterface $e) {
// your logic here
}
use Facile\JoseVerifier\Builder\IdTokenVerifierBuilder;
$builder = IdTokenVerifierBuilder::create($issuerMetadata, $clientMetadata);
$verifier = $builder->build();
use Facile\JoseVerifier\IdTokenVerifierInterface;
/** @var IdTokenVerifierInterface $verifier */
// Provide the `state` used in the Code Grant Flow (this should be provided id the `id_token` contains the `s_hash` claim)
$verifier = $verifier->withState($state);
// Optionally provide these parameters to validate the correct hash values:
$verifier = $verifier
->withAccessToken($accessToken) // Provide the `access_token` used in the Code Grant Flow
->withCode($code) // Provide the `code` used in the Code Grant Flow
try {
$payload = $verifier->verify($jwt);
} catch (InvalidTokenExceptionInterface $e) {
// your logic here
}
use Facile\JoseVerifier\Builder\UserInfoVerifierBuilder;
$builder = UserInfoVerifierBuilder::create($issuerMetadata, $clientMetadata);
$verifier = $builder->build();
try {
$payload = $verifier->verify($jwt);
} catch (InvalidTokenExceptionInterface $e) {
// your logic here
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.