PHP code example of jakub-onderka / openid-connect-php
1. Go to this page and download the library: Download jakub-onderka/openid-connect-php 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/ */
jakub-onderka / openid-connect-php example snippets
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere', 'ClientSecretHere');
$oidc->authenticate();
$name = $oidc->requestUserInfo('given_name');
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient("https://id.provider.com");
$response = $oidc->register("Client Name");
$clientID = $response->client_id;
$clientSecret = $response->client_secret;
// Be sure to add logic to store the client id and client secret
// Configure a proxy
$oidc->setHttpProxy("http://my.proxy.com:80/");
// Configure a cert
$oidc->setCertPath("/path/to/my.cert");
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere', 'ClientSecretHere');
$oidc->providerConfigParam(['token_endpoint' => 'https://id.provider.com/connect/token']);
$oidc->addScope('my_scope');
// This assumes success (to validate check if the access_token property is there and a valid JWT):
$clientCredentialsToken = $oidc->requestClientCredentialsToken()->access_token;
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere','ClientSecretHere');
$oidc->providerConfigParam(['token_endpoint' => 'https://id.provider.com/connect/token']);
$oidc->addScope('my_scope');
// Add username and password
$oidc->addAuthParam([
'username' => '<Username>',
'password' => '<Password>',
]);
// Perform the auth and return the token (to validate check if the access_token property is there and a valid JWT):
$token = $oidc->requestResourceOwnerToken(true)->access_token;
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere', 'ClientSecretHere');
$oidc->setResponseTypes(['id_token']);
$oidc->addScope(['openid']);
$oidc->setAllowImplicitFlow(true);
$oidc->addAuthParam(['response_mode' => 'form_post']);
$oidc->setCertPath('/path/to/my.cert');
$oidc->authenticate();
$sub = $oidc->getVerifiedClaims('sub');
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere', 'ClientSecretHere');
$data = $oidc->introspectToken('an.access-token.as.given');
if (!$data->active) {
// the token is no longer usable
}
use JakubOnderka\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://id.provider.com', 'ClientIDHere');
$oidc->setCodeChallengeMethod('S256');
$oidc->authenticate();
$name = $oidc->requestUserInfo('given_name');