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

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

flipboxdigital/oauth2-guardian
==============================

Craft CMS / Guardian OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1.1.0(8y ago)04.9kMITPHP

Since Sep 22Pushed 8y ago2 watchersCompare

[ Source](https://github.com/flipbox/oauth2-guardian)[ Packagist](https://packagist.org/packages/flipboxdigital/oauth2-guardian)[ RSS](/packages/flipboxdigital-oauth2-guardian/feed)WikiDiscussions master Synced 2w ago

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

Craft CMS / Guardian Provider for OAuth 2.0 Client
==================================================

[](#craft-cms--guardian-provider-for-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/978139ab27e571d684ed31eedaa4816310aeda2937bf298314d73585dab3fdd6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f666c6970626f782f6f61757468322d677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/flipbox/oauth2-guardian/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d283fd60da4990208897ab61c16955a9b79d7ef026459863d277e31d2186e40a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f666c6970626f782f6f61757468322d677561726469616e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/flipbox/oauth2-guardian)[![Coverage Status](https://camo.githubusercontent.com/c3716a62b8bf0ab8aa29da04540d0d24e0532a7d3cde110e38f6511ed6dee8bb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f666c6970626f782f6f61757468322d677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/flipbox/oauth2-guardian/code-structure)[![Quality Score](https://camo.githubusercontent.com/96c149f881868a635398af5dbf6211159022f91f214b330bf4cd6aa822afd421/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f666c6970626f782f6f61757468322d677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/flipbox/oauth2-guardian)[![Total Downloads](https://camo.githubusercontent.com/dde07366afca4d593eb7d38c5c8dc6a2aede07553fda7dd6f9a74908f4312db2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c6970626f786469676974616c2f6f61757468322d677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/flipboxdigital/oauth2-guardian)

This package provides Craft OAuth 2.0 support for [Guardian](https://github.com/flipbox/guardian) and the PHP League's [OAuth 2.0 Client](https://github.com/flipbox/oauth2-client).

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

[](#installation)

To install, use composer:

```
composer require flipboxdigital/oauth2-guardian

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Flipbox\OAuth2\Client\Provider\Guardian([
    'domain'            => 'https://yourdomain.com',
    'apidomain'         => 'https://api.yourdomain.com',
    'clientId'          => '{craft-client-id}',
    'clientSecret'      => '{craft-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();
    $_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->getEmail());

    } 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 Craft authorization URL, you can specify the state and scopes your application may authorize.

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

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

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

Testing
-------

[](#testing)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Flipbox Digital](https://github.com/flipbox)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

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

Total

2

Last Release

3165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f88ef7075dc76a34393f80402c30cc8eec30d5134835314136669a68b8ce817f?d=identicon)[nateiler](/maintainers/nateiler)

---

Top Contributors

[![nateiler](https://avatars.githubusercontent.com/u/1892443?v=4)](https://github.com/nateiler "nateiler (14 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationCraft

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2306.6M50](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

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

1162.9M14](/packages/patrickbussmann-oauth2-apple)[omines/oauth2-gitlab

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

36798.5k16](/packages/omines-oauth2-gitlab)[league/oauth2-instagram

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

661.1M52](/packages/league-oauth2-instagram)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

271.9M1](/packages/mollie-oauth2-mollie-php)[dalpras/oauth2-gotowebinar

LogMeIn GoToWebinar OAuth 2.0 Client Provider for the PHP League's OAuth 2.0 Client

1246.9k](/packages/dalpras-oauth2-gotowebinar)

PHPackages © 2026

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