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

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

sumaerjolly/oauth2-notion
=========================

Notion Oauth 2.0 Client Provider for the PHP league OAuth2 Client

2112↓100%PHP

Since Nov 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sumaerjolly/oauth2-notion)[ Packagist](https://packagist.org/packages/sumaerjolly/oauth2-notion)[ RSS](/packages/sumaerjolly-oauth2-notion/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Notion Online Provider for OAuth 2.0 Client
===========================================

[](#notion-online-provider-for-oauth-20-client)

This package provides Notion 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 sumaerjolly/oauth2-notion

```

### Usage

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

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

if (!isset($_GET['code'])) {
    $options = [
        'scope' => ['default'] // array or string
    ];

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl($options);
    $_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();
}
```

### Managing Scopes

[](#managing-scopes)

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

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => ['default'] // 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](https://developers.notion.com/docs/authorization).

Testing
-------

[](#testing)

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

Credits
-------

[](#credits)

- [Nile Suan](https://github.com/nilesuan)
- [Chad Hutchins](https://github.com/chadhutchins)

License
-------

[](#license)

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

###  Health Score

17

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![sumaerjolly](https://avatars.githubusercontent.com/u/25217715?v=4)](https://github.com/sumaerjolly "sumaerjolly (6 commits)")

### Embed Badge

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

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

###  Alternatives

[firebase/php-jwt

A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.

9.8k435.8M1.8k](/packages/firebase-php-jwt)[league/oauth2-client

OAuth 2.0 Client Library

3.8k115.1M1.0k](/packages/league-oauth2-client)[google/auth

Google Auth Library for PHP

1.4k266.3M125](/packages/google-auth)[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k98.4M87](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99895.6M95](/packages/league-oauth1-client)[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k15.7M42](/packages/lab404-laravel-impersonate)

PHPackages © 2026

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