PHPackages                             maicol07/oidc-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. maicol07/oidc-client

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

maicol07/oidc-client
====================

OpenID Connect client

4.0.2(5mo ago)71.7k↓50%5[1 PRs](https://github.com/maicol07/oidc-client-php/pulls)2Apache-2.0PHPPHP &gt;=8.3CI passing

Since Mar 4Pushed 3mo agoCompare

[ Source](https://github.com/maicol07/oidc-client-php)[ Packagist](https://packagist.org/packages/maicol07/oidc-client)[ Fund](https://paypal.me/maicol072001/10eur)[ GitHub Sponsors](https://github.com/maicol07)[ RSS](/packages/maicol07-oidc-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (48)Used By (2)

PHP OpenID Connect Basic Client
===============================

[](#php-openid-connect-basic-client)

A simple library that allows an application to authenticate a user through the basic OpenID Connect flow. This library hopes to encourage OpenID Connect use by making it simple enough for a developer with little knowledge of the OpenID Connect protocol to setup authentication.

Supported Specifications
------------------------

[](#supported-specifications)

- [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html)
- [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html) ([finding the issuer is missing](https://github.com/jumbojett/OpenID-Connect-PHP/issues/2))
- [OpenID Connect RP-Initiated Logout 1.0 - draft 01](https://openid.net/specs/openid-connect-rpinitiated-1_0.html)
- [OpenID Connect Dynamic Client Registration 1.0](https://openid.net/specs/openid-connect-registration-1_0.html)
- [RFC 6749: The OAuth 2.0 Authorization Framework](https://tools.ietf.org/html/rfc6749)
- [RFC 7009: OAuth 2.0 Token Revocation](https://tools.ietf.org/html/rfc7009)
- [RFC 7636: Proof Key for Code Exchange by OAuth Public Clients](https://tools.ietf.org/html/rfc7636)
- [RFC 7662: OAuth 2.0 Token Introspection](https://tools.ietf.org/html/rfc7662)
- [Draft: OAuth 2.0 Authorization Server Issuer Identifier in Authorization Response](https://tools.ietf.org/html/draft-ietf-oauth-iss-auth-resp-00)

Tested providers
----------------

[](#tested-providers)

> Note: This list is not exhaustive. Other generic OIDC providers should work as well. If you have tested this library with a provider not listed here, please open a PR to add it to the list and add a test configuration (.run directory).

ProviderIs tested?NotesKeycloak✅Client authenticator must be set to "Client id and secret"Casdoor✅Code challenge must be set to S256 or PKCE should be disabledRequirements
------------

[](#requirements)

1. PHP 8.1+
2. JSON extension
3. MBString extension
4. (Optional) One between GMP or BCMath extension to allow faster cipher key operations (for JWT; see [here](https://web-token.spomky-labs.com/introduction/pre-requisite) for more information)

Install
-------

[](#install)

Install using composer:

```
composer require maicol07/oidc-client
```

Examples
--------

[](#examples)

### Example 1: Basic Client

[](#example-1-basic-client)

This example uses the Authorization Code flow and will also use PKCE if the OpenID Provider announces it in his Discovery document. If you are not sure, which flow you should choose: This one is the way to go. It is the most secure and versatile.

```
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;
```

[See OpenID Connect spec for available user attributes](https://openid.net/specs/openid-connect-basic-1_0-15.html#id_res)

### Example 2: Dynamic Registration

[](#example-2-dynamic-registration)

```
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
```

### Example 3: Network and Security

[](#example-3-network-and-security)

You should always use HTTPS for your application. If you are using a self-signed certificate, you can disable the SSL verification by setting the `verify_ssl` property on the client and, if you have it, set a custom certificate in the `cert_path` property (this works only if verifySsl is set to false).

You can also setup a proxy via the `http_proxy`.

```
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',
    http_proxy: 'http://proxy.example.com:8080',
    cert_path: 'path/to/cert.pem',
    verify_ssl: false
);
```

### Example 4: Implicit flow

[](#example-4-implicit-flow)

> Reference: [https://openid.net/specs/openid-connect-core-1\_0.html#ImplicitFlowAuth](https://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth)

The implicit flow should be considered a legacy flow and not used if authorization code grant can be used. Due to its disadvantages and poor security, the implicit flow will be obsoleted with the upcoming OAuth 2.1 standard. See Example 1 for alternatives.

```
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;
```

### Example 5: Introspection of an access token

[](#example-5-introspection-of-an-access-token)

> Reference:

```
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
}
```

### Example 6: PKCE Client

[](#example-6-pkce-client)

PKCE is already configured and used in most scenarios in Example 1. This example shows you how to explicitly set the Code Challenge Method in the initial config. This enables PKCE in case your OpenID Provider doesn’t announce support for it in the discovery document, but supports it anyway.

```
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;
```

### Example 7: Token endpoint authentication method

[](#example-7-token-endpoint-authentication-method)

By default, only `client_secret_basic` is enabled on client side which was the only supported for a long time. Recently `client_secret_jwt` and `private_key_jwt` have been added, but they remain disabled until explicitly enabled.

```
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,
    ]
);
```

**Note: A JWT generator is not included in this library yet.**

Development Environments
------------------------

[](#development-environments)

Sometimes you may need to disable SSL security on your development systems. You can do it by calling the `verify` method with the `false` parameter. Note: This is not recommended on production systems.

```
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
);
```

Testing
-------

[](#testing)

To run the tests, you need to have a running OpenID Connect provider

### Keycloak

[](#keycloak)

1. Run a Keycloak docker container ```
    docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:25.0.5 start-dev
    ```
2. Create a client named with the following settings:
    - Client ID: `oidc`
    - Client authentication: ON
    - Authorization: ON
    - Authentication Flow: Standard Flow, Implicit Flow (if you want to test implicit flow), Direct Access Grants
    - Client Secret: `oidc`
    - Valid Redirect URIs: `http://localhost:9999/callback`
    - Web Origins: `*`
3. Go to Credentials tab and copy the Secret
4. Tweak the PHPStorm Run configuration with your settings.

### Todo

[](#todo)

- Dynamic registration does not support registration auth tokens and endpoints

Contributing
------------

[](#contributing)

- Issues and pull requests are welcome.

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance75

Regular maintenance activity

Popularity28

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~88 days

Recently: every ~71 days

Total

41

Last Release

174d ago

Major Versions

v0.9.2 → v1.0.02021-04-19

1.2 → 2.0a12021-10-18

2.3 → 3.02023-05-31

3.0 → 4.0-rc12024-09-10

PHP version history (5 changes)0.1.0PHP &gt;=5.2

0.3.0PHP &gt;=5.4

2.0a1PHP &gt;=8.0

3.0PHP &gt;=8.1

4.0-rc1PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cf3779f6b891b03274b9477410134fc585a7dfba6de85ee720fa7e155f92d79?d=identicon)[maicol07](/maintainers/maicol07)

---

Top Contributors

[![jumbojett](https://avatars.githubusercontent.com/u/410057?v=4)](https://github.com/jumbojett "jumbojett (176 commits)")[![maicol07](https://avatars.githubusercontent.com/u/9463142?v=4)](https://github.com/maicol07 "maicol07 (90 commits)")[![JuliusPC](https://avatars.githubusercontent.com/u/15018932?v=4)](https://github.com/JuliusPC "JuliusPC (43 commits)")[![DeepDiver1975](https://avatars.githubusercontent.com/u/1005065?v=4)](https://github.com/DeepDiver1975 "DeepDiver1975 (15 commits)")[![rasodu](https://avatars.githubusercontent.com/u/13222196?v=4)](https://github.com/rasodu "rasodu (9 commits)")[![radenui](https://avatars.githubusercontent.com/u/9445250?v=4)](https://github.com/radenui "radenui (9 commits)")[![kenguest](https://avatars.githubusercontent.com/u/234118?v=4)](https://github.com/kenguest "kenguest (7 commits)")[![morcs](https://avatars.githubusercontent.com/u/555420?v=4)](https://github.com/morcs "morcs (6 commits)")[![guss77](https://avatars.githubusercontent.com/u/381782?v=4)](https://github.com/guss77 "guss77 (5 commits)")[![jdreed](https://avatars.githubusercontent.com/u/4193101?v=4)](https://github.com/jdreed "jdreed (5 commits)")[![baru](https://avatars.githubusercontent.com/u/688602?v=4)](https://github.com/baru "baru (5 commits)")[![nikosev](https://avatars.githubusercontent.com/u/29930145?v=4)](https://github.com/nikosev "nikosev (4 commits)")[![corentingi](https://avatars.githubusercontent.com/u/3458976?v=4)](https://github.com/corentingi "corentingi (4 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (3 commits)")[![seth-xdam](https://avatars.githubusercontent.com/u/22687020?v=4)](https://github.com/seth-xdam "seth-xdam (3 commits)")[![stijnster](https://avatars.githubusercontent.com/u/27271?v=4)](https://github.com/stijnster "stijnster (3 commits)")[![adambartholomew](https://avatars.githubusercontent.com/u/324503?v=4)](https://github.com/adambartholomew "adambartholomew (3 commits)")[![JTubex](https://avatars.githubusercontent.com/u/5894935?v=4)](https://github.com/JTubex "JTubex (3 commits)")[![lordelph](https://avatars.githubusercontent.com/u/444004?v=4)](https://github.com/lordelph "lordelph (3 commits)")[![n0nag0n](https://avatars.githubusercontent.com/u/2322095?v=4)](https://github.com/n0nag0n "n0nag0n (3 commits)")

---

Tags

oidcoidc-clientoidc-provideropenidopenid-connectphpphp8php81clientSSOoauth 2OpenID Connectoidcrfc7636rfc6749RFC7009RFC7662

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/maicol07-oidc-client/health.svg)

```
[![Health](https://phpackages.com/badges/maicol07-oidc-client/health.svg)](https://phpackages.com/packages/maicol07-oidc-client)
```

###  Alternatives

[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2641.6M2](/packages/josiasmontag-laravel-recaptchav3)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[authlete/authlete-laravel

Authlete Library for Laravel

4226.0k](/packages/authlete-authlete-laravel)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5016.9k1](/packages/simplesamlphp-simplesamlphp-module-oidc)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

2073.7k](/packages/kovah-laravel-socialite-oidc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
