PHPackages                             chrishemmings/oauth2-drupal - 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. chrishemmings/oauth2-drupal

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

chrishemmings/oauth2-drupal
===========================

Drupal OAuth2-Server Client Provider for The PHP League OAuth2-Client

2.0.0(9y ago)815.9k3MITPHP

Since Mar 5Pushed 4y ago2 watchersCompare

[ Source](https://github.com/chrishemmings/oauth2-drupal)[ Packagist](https://packagist.org/packages/chrishemmings/oauth2-drupal)[ RSS](/packages/chrishemmings-oauth2-drupal/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

Drupal OAuth2-Server support for the PHP League's OAuth 2.0 Client
==================================================================

[](#drupal-oauth2-server-support-for-the-php-leagues-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/14f0278e0a0502bf73081daf80bf8b8885addcf541592468c5ef6584aac55b0e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636872697368656d6d696e67732f6f61757468322d64727570616c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/chrishemmings/oauth2-drupal/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/7ca3c5bd99279e2a4c180cdd4699c9970b64a679ed07a62743c0b209b755819e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636872697368656d6d696e67732f6f61757468322d64727570616c2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/chrishemmings/oauth2-drupal)[![Quality Score](https://camo.githubusercontent.com/2f6329a3579e139d665427a6803d7d6af864b784ffa7f271b339a9893aec4739/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f636872697368656d6d696e67732f6f61757468322d64727570616c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/chrishemmings/oauth2-drupal)[![Total Downloads](https://camo.githubusercontent.com/e00bd39d87f199505bbba7237d99005bd029a40849facadbf99a03c3da0e2dba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636872697368656d6d696e67732f6f61757468322d64727570616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chrishemmings/oauth2-drupal)

This package provides Drupal OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

Installation
------------

[](#installation)

To install, use composer:

```
composer require chrishemmings/oauth2-drupal

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\ChrisHemmings\OAuth2\Client\Provider\Drupal` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
require_once('./vendor/autoload.php');
session_start();

$provider = new \ChrisHemmings\OAuth2\Client\Provider\Drupal([
    'clientId'          => '{drupal-client-id}',
    'clientSecret'      => '{drupal-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
    'baseUrl'           => 'https://example.com',
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getName());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/chrishemmings/oauth2-drupal/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Chris Hemmings](https://github.com/chrishemmings)
- [All Contributors](https://github.com/chrishemmings/oauth2-drupal/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/chrishemmings/oauth2-drupal/blob/master/LICENSE) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

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 ~90 days

Total

5

Last Release

3409d ago

Major Versions

1.x-dev → 2.0.02017-03-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/8639948042c5affb0d40f2062b692b11ef04659c7d86d4a47ca9b0e7243e3bd6?d=identicon)[chrishemmings](/maintainers/chrishemmings)

---

Top Contributors

[![chrishemmings](https://avatars.githubusercontent.com/u/7426965?v=4)](https://github.com/chrishemmings "chrishemmings (6 commits)")[![anshprat](https://avatars.githubusercontent.com/u/333902?v=4)](https://github.com/anshprat "anshprat (1 commits)")

---

Tags

AuthenticationdrupalSSOidentityoauthoauth2authorizationidpsingle sign on

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chrishemmings-oauth2-drupal/health.svg)

```
[![Health](https://phpackages.com/badges/chrishemmings-oauth2-drupal/health.svg)](https://phpackages.com/packages/chrishemmings-oauth2-drupal)
```

###  Alternatives

[calcinai/oauth2-xero

Xero OAuth 2.0 Client Provider for The PHP League OAuth2-Client

103.4M4](/packages/calcinai-oauth2-xero)[adam-paterson/oauth2-slack

Slack OAuth 2.0 Client Provider for The PHP League OAuth2-Client

22749.0k10](/packages/adam-paterson-oauth2-slack)

PHPackages © 2026

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