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

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

ominity/oauth2-ominity-php
==========================

Ominity Provider for OAuth 2.0 Client

v1.0.0(2y ago)020BSD-2-ClausePHPPHP ^7.4|^8.0

Since May 14Pushed 2y agoCompare

[ Source](https://github.com/ominity/oauth2-ominity-php)[ Packagist](https://packagist.org/packages/ominity/oauth2-ominity-php)[ Docs](https://github.com/ominity/oauth2-ominity-php)[ RSS](/packages/ominity-oauth2-ominity-php/feed)WikiDiscussions main Synced 1mo ago

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

Ominity OAuth in PHP
====================

[](#ominity-oauth-in-php)

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

Use Ominity OAuth to easily connect Ominity User &amp; Admin accounts to your application.

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

[](#installation)

By far the easiest way to install the Ominity API client is to require it with [Composer](http://getcomposer.org/doc/00-intro.md).

```
$ composer require ominity/oauth2-ominity-php ^1.0

    {
        "require": {
            "ominity/oauth2-ominity-php": "^1.0"
        }
    }

```

You may also git checkout or [download all the files](https://github.com/ominity/oauth2-ominity-php/archive/master.zip), and include the OAuth 2.0 provider manually.

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new \Ominity\OAuth2\Client\Provider\Ominity([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

// If we don't have an authorization code then get one
if (!isset($_GET['code']))
{
    // Fetch the authorization URL from the provider; this returns the
    // urlAuthorize option and generates and applies any necessary parameters
    // (e.g. state).
    $authorizationUrl = $provider->getAuthorizationUrl([
        // Optional, only use this if you want to ask for scopes the user previously denied.
        'approval_prompt' => 'force',

        // Optional, a list of scopes. Defaults to only 'me.read'.
        'scope' => [
        \Ominity\OAuth2\Client\Provider\Ominity::SCOPE_ME_READ,
	    \Ominity\OAuth2\Client\Provider\Ominity::SCOPE_USERS_READ
	],
    ]);

    // Get the state generated for you and store it to the session.
    $_SESSION['oauth2state'] = $provider->getState();

    // Redirect the user to the authorization URL.
    header('Location: ' . $authorizationUrl);
    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
    {
        // Try to get an access token using the authorization code grant.
        $accessToken = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // Using the access token, we may look up details about the resource owner.
        $resourceOwner = $provider->getResourceOwner($accessToken);

        print_r($resourceOwner->toArray());
    }
    catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e)
    {
        // Failed to get the access token or user details.
        exit($e->getMessage());
    }
}
```

### Refreshing A Token

[](#refreshing-a-token)

```
$provider = new \Ominity\OAuth2\Client\Provider\Ominity([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

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

### Authenticating using the AccessToken (ominity-api-php example)

[](#authenticating-using-the-accesstoken-ominity-api-php-example)

After refreshing an AccessToken, here's how to use it with the [ominity-api-php package](https://www.github.com/ominity/ominity-api-php). Note that the `getToken()` method is used to obtain the access token string.

```
$ominity = new \Ominity\Api\OminityApiClient;
$ominity->setAccessToken($token->getToken());

// With the correct scopes, you can now interact with Ominity's API on behalf of the User
$orders = $ominity->commerce->orders->page(); // returns paginated user orders
```

Note

In order to access the ominity api via `\Ominity\Api\OminityApiClient`, the [ominity/ominity-api-php](github.com/ominity/ominity-api-php) library is required!

### Revoking a token

[](#revoking-a-token)

Both AccessTokens and RefreshTokens are revokable. Here's how to revoke an AccessToken:

```
$provider = new \Ominity\OAuth2\Client\Provider\Ominity([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

$provider->revokeAccessToken($accessToken->getToken());
```

Similarly, here's how to revoke a RefreshToken:

**Note: When you revoke a refresh token, all access tokens based on the same authorization grant will be revoked as well.**

```
$provider = new \Ominity\OAuth2\Client\Provider\Ominity([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

$provider->revokeRefreshToken($refreshToken->getToken());
```

Want to help us make our API client even better?
------------------------------------------------

[](#want-to-help-us-make-our-api-client-even-better)

Want to help us make our API client even better? We take [pull requests](https://github.com/ominity/ominity-api-php/pulls?utf8=%E2%9C%93&q=is%3Apr).

License
-------

[](#license)

[BSD (Berkeley Software Distribution) License](http://www.opensource.org/licenses/bsd-license.php). Copyright (c) 2024, Ominity.

Support
-------

[](#support)

Contact: [www.ominity.com](https://www.ominity.com) —

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

734d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7924ffc05230e682beedd22b0644fc1f80e78e79dd285bbacad764cf9fbb7649?d=identicon)[ominity](/maintainers/ominity)

---

Top Contributors

[![timdesm](https://avatars.githubusercontent.com/u/30378686?v=4)](https://github.com/timdesm "timdesm (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationominity

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

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