PHP implementation of https://openid.net/specs/openid-connect-core-1_0.html
Via Composer
$ composer require digitalcz/openid-connect
use DigitalCz\OpenIDConnect\ClientMetadata;
use DigitalCz\OpenIDConnect\ClientFactory;
$issuerUrl = 'https://example.com';
$clientMetadata = new ClientMetadata('clientid', 'clientsecret', 'https://example.com/callback');
$client = ClientFactory::create($issuerUrl, $clientMetadata);
Manually
use DigitalCz\OpenIDConnect\Client;
use DigitalCz\OpenIDConnect\ClientMetadata;
use DigitalCz\OpenIDConnect\Config;
use DigitalCz\OpenIDConnect\Http\HttpClientFactory;
use DigitalCz\OpenIDConnect\Token\TokenVerifierFactory;
use DigitalCz\OpenIDConnect\ProviderMetadata;
$clientMetadata = new ClientMetadata('clientid', 'clientsecret', 'https://example.com/callback');
$providerMetadata = new ProviderMetadata([
ProviderMetadata::AUTHORIZATION_ENDPOINT => 'https://example.com/authorize',
ProviderMetadata::TOKEN_ENDPOINT => 'https://example.com/token',
// ...
])
$config = new Config($providerMetadata, $clientMetadata);
$client = new Client($config, HttpClientFactory::create());
use DigitalCz\OpenIDConnect\Param\AuthorizationParams;
$state = bin2hex(random_bytes(8));
$_SESSION['oauth_state'] = $state;
$authorizationParams = new AuthorizationParams([
AuthorizationParams::SCOPE => 'openid profile',
AuthorizationParams::STATE => $state,
]);
$url = $client->getAuthorizationUrl($authorizationParams);
header('Location: ' . $url);
exit();
use DigitalCz\OpenIDConnect\Param\CallbackParams;
use DigitalCz\OpenIDConnect\Param\CallbackChecks;
$tokens = $client->handleCallback(
new CallbackParams($_GET),
new CallbackChecks($_SESSION['oauth_state'])
);
use DigitalCz\OpenIDConnect\Grant\ClientCredentials;
use DigitalCz\OpenIDConnect\Param\TokenParams;
$tokens = $client->requestTokens(
new TokenParams(
new ClientCredentials(),
[
TokenParams::SCOPE => 'some scope'
]
)
);
See examples for more
Please see CHANGELOG for more information on what has changed recently.
$ composer csfix # fix codestyle
$ composer checks # run all checks
# or separately
$ composer tests # run phpunit
$ composer phpstan # run phpstan
$ composer cs # run codesniffer
Please see CONTRIBUTING for details.
If you discover any security related issues, please email devs@digital.cz instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.