1. Go to this page and download the library: Download maicol07/oidc-client 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/ */
maicol07 / oidc-client example snippets
use Maicol07\OpenIDConnect\Client;
$oidc = new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php',
);
$oidc->authenticate();
$name = $oidc->getUserInfo()->given_name;
use Maicol07\OpenIDConnect\Client;
$oidc = new Client(
provider_url: 'https://id.example.com',
redirect_uri: 'https://example.com/callback.php',
client_name: 'My Client',
);
$oidc->register();
[$client_id, $client_secret] = $oidc->getClientCredentials();
// Be sure to add logic to store the client id and client secret
use Maicol07\OpenIDConnect\Client;
use Maicol07\OpenIDConnect\ResponseType;
$oidc = new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php',
response_type: ResponseType::ID_TOKEN,
allow_implicit_flow: true,
);
$oidc->authenticate();
$sub = $oidc->getUserInfo()->sub;
use Maicol07\OpenIDConnect\Client;
$oidc = new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php'
);
$data = $oidc->introspectToken('an.access-token.as.given');
if (!$data->get('active')) {
// the token is no longer usable
}
use Maicol07\OpenIDConnect\Client;
use Maicol07\OpenIDConnect\CodeChallengeMethod;
$oidc = new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php',
// for some reason we want to set S256 explicitly as Code Challenge Method
// maybe your OP doesn’t announce support for PKCE in its discovery document.
code_challenge_method: CodeChallengeMethod::S256
);
$oidc->authenticate();
$name = $oidc->getUserInfo()->given_name;
use Maicol07\OpenIDConnect\Client;
use Maicol07\OpenIDConnect\TokenEndpointAuthMethod;
$oidc = new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php',
token_endpoint_auth_methods_supported: [
TokenEndpointAuthMethod::CLIENT_SECRET_BASIC,
TokenEndpointAuthMethod::CLIENT_SECRET_JWT,
TokenEndpointAuthMethod::PRIVATE_KEY_JWT,
]
);
use Maicol07\OpenIDConnect\Client;
$oidc new Client(
provider_url: 'https://id.example.com',
client_id: 'ClientIDHere',
client_secret: 'ClientSecretHere',
redirect_uri: 'https://example.com/callback.php',
verify_ssl: false
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.