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

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

chainels/oauth2-chainels
========================

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

v2.0.0(9y ago)02.6kMITPHPPHP &gt;=5.6

Since Mar 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Chainels/oauth2-provider-php)[ Packagist](https://packagist.org/packages/chainels/oauth2-chainels)[ RSS](/packages/chainels-oauth2-chainels/feed)WikiDiscussions master Synced today

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

Chainels Provider for OAuth 2.0 Client
======================================

[](#chainels-provider-for-oauth-20-client)

[![](https://camo.githubusercontent.com/422a67eca27d2fd9f6d7562ae00b9bf0a54abe3bce87f31ae5917c5b3353d3be/68747470733a2f2f63646e2e636861696e656c732e636f6d2f696d6167652f333131353638313933363035333235353237)](https://camo.githubusercontent.com/422a67eca27d2fd9f6d7562ae00b9bf0a54abe3bce87f31ae5917c5b3353d3be/68747470733a2f2f63646e2e636861696e656c732e636f6d2f696d6167652f333131353638313933363035333235353237)

[![Latest Stable Version](https://camo.githubusercontent.com/a49f732e4811d7dd75ed9ca75f9437ff6035506d3597c929b1e2e29457f2041a/68747470733a2f2f706f7365722e707567782e6f72672f636861696e656c732f6f61757468322d636861696e656c732f762f737461626c65)](https://packagist.org/packages/chainels/oauth2-chainels) [![Total Downloads](https://camo.githubusercontent.com/f77cc60f13c0ff5f09ec992d61343065ae869b0795a7d6acd981a758a45ecc71/68747470733a2f2f706f7365722e707567782e6f72672f636861696e656c732f6f61757468322d636861696e656c732f646f776e6c6f616473)](https://packagist.org/packages/chainels/oauth2-chainels) [![Latest Unstable Version](https://camo.githubusercontent.com/3c34bf61ddfbdee2642430d26163f1629fe1836c1f46a2a8b98f8c83f1140427/68747470733a2f2f706f7365722e707567782e6f72672f636861696e656c732f6f61757468322d636861696e656c732f762f756e737461626c65)](https://packagist.org/packages/chainels/oauth2-chainels) [![License](https://camo.githubusercontent.com/1710a8ee5ddc1670341315393dd67edcffce4caafbf414126ed2755a15cbc88d/68747470733a2f2f706f7365722e707567782e6f72672f636861696e656c732f6f61757468322d636861696e656c732f6c6963656e7365)](https://packagist.org/packages/chainels/oauth2-chainels) [![Build Status](https://camo.githubusercontent.com/a98e6d90cfc4eb2c1da5ae6e00cf59fdb369c36e8b030d3f791def4cfc954fbd/68747470733a2f2f7472617669732d63692e6f72672f436861696e656c732f6f61757468322d70726f76696465722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Chainels/oauth2-provider-php) [![Coverage Status](https://camo.githubusercontent.com/e1275d918b5c63fdbe72e8ed59e3c6285b48fad9cabf62ac064a61640857302f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f436861696e656c732f6f61757468322d70726f76696465722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Chainels/oauth2-provider-php?branch=master)

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

Install
-------

[](#install)

Via Composer:

```
$ composer require chainels/oauth2-chainels

```

Version 2.\* of this library requires PHP 5.6 or up. If you need support for PHP 5.5, use version 1.\*, though we recommend upgrading your PHP version.

Register Oauth Client
---------------------

[](#register-oauth-client)

In order to use this library, you must create an OAuth client on Chainels.com, to do this, you must have an account and company on Chainels. For more details, check our [developer page](https://www.chainels.com/developer).

Usage
-----

[](#usage)

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

### Requesting an access token

[](#requesting-an-access-token)

Chainels supports the authorization code grant, the client credentials grant, and our own custom group token grant, for requesting an access token.

#### Authorization Code Grant

[](#authorization-code-grant)

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

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

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl(['grant_type' => 'authorization_code']);
    $_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. You can also use this token for other HTTP calls to the REST API */
    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 the Chainels API on the users behalf
    echo $token->getToken();
}
```

#### Client Credential Grant

[](#client-credential-grant)

```
$provider = new Chainels\OAuth2\Client\Provider\Chainels([
    'clientId'          => '{chainels-client-id}',
    'clientSecret'      => '{chainels-client-secret}',
]);

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

// Use this to interact with the Chainels API
echo $token->getToken();
}
```

#### Group Token Grant

[](#group-token-grant)

This is the same as the authorization code grant, except make sure to pass a `group` parameter to the `getAuthorizationUrl()` method.

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

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

    // If we don't have an authorization code then get one, here we specify the group
    $authUrl = $provider->getAuthorizationUrl(['grant_type' => 'group_token', 'group' => '1234']);
    $_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('group_token', [
        'code' => $_GET['code']
    ]);

    /* Optional: Now you have a token you can look up a users profile data. You can also use this token for other HTTP calls to the REST API */
    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();
}
```

### Refreshing a Token

[](#refreshing-a-token)

Once your application is authorized, you can refresh an expired token using a refresh token rather than going through the entire process of obtaining a brand new token. To do so, simply reuse this refresh token from your data store to request a refresh.

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

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $newAccessToken = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingAccessToken->getRefreshToken()
    ]);

    // Purge old access token and store new access token to your data store.
}
```

### Making authenticated API requests

[](#making-authenticated-api-requests)

Once you have an access token, this library provides a simple mechanism to make authenticated calls to our api.

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

$accessToken = getAccessTokenFromYourDataStore();

// getAuthenticatedRequest returns a Psr\Http\Message\RequestInterface object
$request = $provider->getAuthenticatedRequest('GET', 'https://www.chainels.com/api/v2/companies/{id}', $accessToken);

//this RequestInterface can then be passed to the getParsedResponse() method to execute the request:
$responseJSON = $provider->getParsedResponse($request);
```

`$responseJSON` now contains the response data as a key-&gt;value array. If you want the full `Psr\Http\Message\ResponseInterface` instead of a parsed result, simply call `getResponse()` instead of `getParsedResponse()`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~245 days

Total

3

Last Release

3285d ago

Major Versions

v1.0.0 → v2.0.02017-07-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/7edf7e94c49ea44afbc6c6aa8e5d8e1e3bf7679a9b43956c194af710f4d647b6?d=identicon)[ChrisTitos](/maintainers/ChrisTitos)

---

Top Contributors

[![ChrisTitos](https://avatars.githubusercontent.com/u/2377451?v=4)](https://github.com/ChrisTitos "ChrisTitos (18 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

25310.7M83](/packages/thenetworg-oauth2-azure)[league/oauth2-google

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

42223.4M176](/packages/league-oauth2-google)[stevenmaguire/oauth2-keycloak

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

2306.4M45](/packages/stevenmaguire-oauth2-keycloak)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1152.8M12](/packages/patrickbussmann-oauth2-apple)

PHPackages © 2026

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