PHPackages                             alimir/oauth2-envato - 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. alimir/oauth2-envato

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

alimir/oauth2-envato
====================

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

v0.1.1-beta.4(10y ago)031[1 PRs](https://github.com/Alimir/oauth2-envato/pulls)MITPHPPHP &gt;=5.5.0

Since Feb 5Pushed 6y agoCompare

[ Source](https://github.com/Alimir/oauth2-envato)[ Packagist](https://packagist.org/packages/alimir/oauth2-envato)[ RSS](/packages/alimir-oauth2-envato/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (4)Used By (0)

Envato Provider for PHP League OAuth 2.0 Client
===============================================

[](#envato-provider-for-php-league-oauth-20-client)

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

[](#installation)

To install, use composer:

`composer require smachi/envato-oauth2-provider`

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

[](#authorization-code-flow)

```
$provider = new \Alimir\OAuth2\Client\Provider\Envato([
    'clientId'          => '{envato-client-id}',
    'clientSecret'      => '{envato-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();

	return new RedirectResponse( $authUrl );

}
// 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');
}

// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken( 'authorization_code', [
	'code' => $_GET['code']
] );

try {

	// We got an access token, let's now get the user's details
    $owner          = $provider->getResourceOwner( $token, 'username' );
    $ownerEmail     = $provider->getResourceOwner( $token, 'email' );
    $ownerPurchases = $provider->getResourceOwner( $token, 'purchases', [ 'filter_by' => 'wordpress-themes' ] );

    $username   = preg_replace( '/[^a-z0-9-_]/i', '', $owner->getUsername() );
    $email      = $ownerEmail->getEmail();
    $purchases  = $ownerPurchases->getPurchases();
    $authorName = 'YourEnvatoAuthorUserName';

    if ( empty( $purchases ) ) {
        throw new \Exception(
            "Only current buyers have access to $authorName support forums.",
            401
        );
    }
    else{

        // Check for item support validity
        $maybePurchaseFromAuthor = FALSE;

        foreach($purchases as $item){

            if ( $authorName == $item['item']['author_username'] ){

                $maybePurchaseFromAuthor = TRUE;
                if ( strtotime( $item['supported_until'] ) > time() ){
                    // The support license is still valid
                    $itemUrl = $item['item']['url'];
                    break;
                }

            }

        }

        // Support expired
        if ( $maybePurchaseFromAuthor ){

            if ( ! $itemUrl ) {
                throw new \Exception(
                    'Your support license has expired.Please renew it and come back again to get access.',
                    901
                );
            }

        }
        // Did not purchase any item from author
        else{
            throw new \Exception(
                "Only current buyers have access to $authorName support forums.",
                401
            );
        }

    }

} catch (\Exception $e){
	die( $e->getMessage() );
}

```

Some Auth User Data
-------------------

[](#some-auth-user-data)

### $provider-&gt;getResourceOwner( $token, 'username' )

[](#provider-getresourceowner-token-username-)

Object:

```
$user->getUsername()

```

### $provider-&gt;getResourceOwner( $token, 'email' )

[](#provider-getresourceowner-token-email-)

Object:

```
$user->getEmail()

```

### $provider-&gt;getResourceOwner( $token, 'purchases', \[ 'filter\_by' =&gt; 'NULL | wordpress-themes | wordpress-plugins' \] )

[](#provider-getresourceowner-token-purchases--filter_by--null--wordpress-themes--wordpress-plugins--)

Object:

```
$user->getPurchases()

$user->getPurchasesCount()

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

Total

3

Last Release

3745d ago

### Community

Maintainers

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

---

Top Contributors

[![smachi](https://avatars.githubusercontent.com/u/6269226?v=4)](https://github.com/smachi "smachi (11 commits)")[![Alimir](https://avatars.githubusercontent.com/u/5402590?v=4)](https://github.com/Alimir "Alimir (3 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationenvato

### Embed Badge

![Health badge](/badges/alimir-oauth2-envato/health.svg)

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

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