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

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

ahoicloud/oauth2-client
=======================

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

1.1.1(8y ago)024[2 PRs](https://github.com/ahoicloud/oauth2-client/pulls)MITPHP

Since Dec 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ahoicloud/oauth2-client)[ Packagist](https://packagist.org/packages/ahoicloud/oauth2-client)[ RSS](/packages/ahoicloud-oauth2-client/feed)WikiDiscussions master Synced 3d ago

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

Ahoi Provider for OAuth 2.0 Client
==================================

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

[![Latest Version](https://camo.githubusercontent.com/80168b268424de2f06f64712efe8e7f653c1b1c722150bdc046a582fdae9932a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f61686f69636c6f75642f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/ahoicloud/oauth2-client/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/363c02d5126e94168c05e8be489d9b411f30330cb408361215f088a6c3544fda/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f61686f69636c6f75642f6f61757468322d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ahoicloud/oauth2-client)[![Coverage Status](https://camo.githubusercontent.com/85674f591d31c6c30eb73db914b21b2ec19598c5c0b618b9800d8b73cf797f3b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f61686f69636c6f75642f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ahoicloud/oauth2-client/code-structure)[![Quality Score](https://camo.githubusercontent.com/f810836bd9db838a9adef17a04973a5b1823506893600aa8cb3cc337617c7f00/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f61686f69636c6f75642f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ahoicloud/oauth2-client)[![Total Downloads](https://camo.githubusercontent.com/05b80fe9e58d1205af0e02ed87b0d02d4ca63a811846f7b16a1429b9f989c45e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61686f69636c6f75642f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahoicloud/oauth2-client)

This package provides Ahoi 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 ahoicloud/oauth2-client

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

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

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->getFirstname());

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

### Managing Scopes

[](#managing-scopes)

When creating your Ahoi authorization URL, you can specify the state and scopes your application may authorize.

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => ['profile','offline_acccess'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the following scopes are available.

- profile
- offline\_acccess

### Refreshing a Token

[](#refreshing-a-token)

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

$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);
```

### Client Credentials Grant

[](#client-credentials-grant)

When your application is acting on its own behalf to access resources it controls/owns in a service provider, it may use the client credentials grant type. This is best used when the credentials for your application are stored privately and never exposed (e.g. through the web browser, etc.) to end-users. This grant type functions similarly to the resource owner password credentials grant type, but it does not request a user's username or password. It uses only the client ID and secret issued to your client by the service provider.

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

try {

    // Try to get an access token using the client credentials grant.
    $accessToken = $provider->getAccessToken('client_credentials');

} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {

    // Failed to get the access token
    exit($e->getMessage());

}
```

Testing
-------

[](#testing)

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

Credits
-------

[](#credits)

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/ahoicloud/oauth2-client/contributors)

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 78.6% 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 ~3 days

Total

5

Last Release

3060d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f54ad4bbe4d0893e800b6d79561d7f2afb0827aee755ca11cab8fb0ed703836?d=identicon)[arnebr](/maintainers/arnebr)

---

Top Contributors

[![arnebr](https://avatars.githubusercontent.com/u/1068416?v=4)](https://github.com/arnebr "arnebr (11 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (3 commits)")

---

Tags

ahoicloudoauth2-clientoauth2-providerclientoauthoauth2authorizationauthorisationahoicloud

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

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

1132.5M6](/packages/patrickbussmann-oauth2-apple)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

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

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

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