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

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

mehdibo/oauth2-fortytwo
=======================

42 Intranet OAuth 2.0 support for the PHP League's OAuth 2.0 Client

v1.0.1(3y ago)47301MITPHPPHP ^7.4|^8.0

Since Feb 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mehdibo/oauth2-fortytwo)[ Packagist](https://packagist.org/packages/mehdibo/oauth2-fortytwo)[ RSS](/packages/mehdibo-oauth2-fortytwo/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (3)Dependencies (4)Versions (6)Used By (1)

42 Intranet OAuth 2.0 provider for the PHP League's OAuth 2.0 Client
====================================================================

[](#42-intranet-oauth-20-provider-for-the-php-leagues-oauth-20-client)

[![Latest Stable Version](https://camo.githubusercontent.com/befd519edffbf16c39accd4684c74698c6d1c888ee7eb86354d7aa1d2dfe8d34/68747470733a2f2f706f7365722e707567782e6f72672f6d65686469626f2f6f61757468322d666f72747974776f2f76)](//packagist.org/packages/mehdibo/oauth2-fortytwo)[![Latest Unstable Version](https://camo.githubusercontent.com/b7aface7c3332a1bec9d7064d3b94ac781e039e01b9f9361d87b7acb60815676/68747470733a2f2f706f7365722e707567782e6f72672f6d65686469626f2f6f61757468322d666f72747974776f2f762f756e737461626c65)](//packagist.org/packages/mehdibo/oauth2-fortytwo)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Unit tests](https://github.com/mehdibo/oauth2-fortytwo/workflows/Unit%20tests/badge.svg?branch=main)](https://github.com/mehdibo/oauth2-fortytwo/workflows/Unit%20tests/badge.svg?branch=main)[![Packagist Downloads](https://camo.githubusercontent.com/0061a4dafe285ade77d3526ee09a3493bcd79360f8d2606737e27444a7d8186a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d65686469626f2f6f61757468322d666f72747974776f)](https://camo.githubusercontent.com/0061a4dafe285ade77d3526ee09a3493bcd79360f8d2606737e27444a7d8186a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d65686469626f2f6f61757468322d666f72747974776f)

This package provides 42 Intranet's 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 mehdibo/oauth2-fortytwo

```

Usage
-----

[](#usage)

Using with Symfony
------------------

[](#using-with-symfony)

You can use this library with [knpuniversity/oauth2-client-bundle](https://github.com/knpuniversity/oauth2-client-bundle)

Install [knpuniversity/oauth2-client-bundle](https://github.com/knpuniversity/oauth2-client-bundle) using composer:

```
composer require knpuniversity/oauth2-client-bundle

```

Install mehdibo/oauth2-fortytwo:

```
composer require mehdibo/oauth2-fortytwo

```

Add these lines to your `.env` file:

```
###> mehdibo/oauth2-fortytwo ###
OAUTH_FT_ID=
OAUTH_FT_SECRET=
###< mehdibo/oauth2-fortytwo ###

```

Configure the bundle to use FT's client, by updating `config/packages/knpu_oauth2_client.yml`:

```
knpu_oauth2_client:
    clients:
        forty_two:
            type: generic
            provider_class: Mehdibo\OAuth2\Client\Provider\FortyTwo
            client_id: '%env(OAUTH_FT_ID)%'
            client_secret: '%env(OAUTH_FT_SECRET)%'
            redirect_route: auth_social_fortytwo_check # Here is the name of the route that will be used to check the code
```

Create the controller to handle the authentication logic, check [this](https://github.com/knpuniversity/oauth2-client-bundle#authenticating-with-guard) for more details about that.

```
# src/Controller/FortyTwoController.php

namespace App\Controller;

use ApiPlatform\Core\OpenApi\Model\Operation;
use ApiPlatform\Core\OpenApi\Model\PathItem;
use ApiPlatform\Core\OpenApi\OpenApi;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class FortyTwoController extends AbstractController
{

    #[Route('/auth/login/fortytwo', name: 'auth_social_fortytwo_start')]
    public function connect(ClientRegistry $clientRegistry): RedirectResponse
    {
        return $clientRegistry
            ->getClient('forty_two')
            ->redirect([], []);
    }

    #[Route('/auth/login/fortytwo/check', name: 'auth_social_fortytwo_check')]
    public function connectCheck(Request $request, ClientRegistry $clientRegistry): void
    {
        throw new \LogicException("This should be caught by the guard authenticator");
    }
}
```

The final step is to create an Authentication guard

Authorization Code Flow
-----------------------

[](#authorization-code-flow)

```
$provider = new \Mehdibo\OAuth2\Client\Provider\FortyTwo([
    'clientId'          => '{uid}',
    'clientSecret'      => '{secret}',
    'redirectUri'       => '{redirect-uri}',
]);

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
        /**
         * @var $user \Mehdibo\OAuth2\Client\Provider\ResourceOwner
        */
        $user = $provider->getResourceOwner($token);

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

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

You can add extra scopes by passing them to the `getAuthorizationUrl()` method

```
$options = [
    'scope' => ['public','profile','projects']
];

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

If no scopes are passed, only `public` is used

Testing
-------

[](#testing)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Total

4

Last Release

1371d ago

Major Versions

v0.1.0 → v1.0.0-beta2021-02-15

### Community

Maintainers

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

---

Top Contributors

[![mehdibo](https://avatars.githubusercontent.com/u/5004111?v=4)](https://github.com/mehdibo "mehdibo (55 commits)")

---

Tags

phpapiclientAuthenticationoauthoauth2authorization42fortytwoft42 school1337

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[league/oauth2-facebook

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

32013.0M66](/packages/league-oauth2-facebook)[andalisolutions/oauth2-anaf

Anaf OAuth 2.0 support for the PHP League's OAuth 2.0 Client

194.1k](/packages/andalisolutions-oauth2-anaf)

PHPackages © 2026

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