PHPackages                             marcospaulosss/jwt - 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. marcospaulosss/jwt

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

marcospaulosss/jwt
==================

JWT authentication Phalcon 3 based in Json Web Token

069PHP

Since Jun 18Pushed 7y agoCompare

[ Source](https://github.com/marcospaulosss/JWT)[ Packagist](https://packagist.org/packages/marcospaulosss/jwt)[ RSS](/packages/marcospaulosss-jwt/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

JWT Phalcon 3.x - Gauth
=======================

[](#jwt-phalcon-3x---gauth)

Auth library for Phalcon 3.x based on JWT standard that can be used on traditional websites or API based applications. It is recommended to upgrade your PHP installation to 5.6. because in Phalcon 3.0.0 the support for PHP 5.4 has been deprecated and in PHP 5.5 some unsafe functions has been also deprecated.

\###Requirements

- Phalcon 3.x
- PHP 5.6

\###Installation

- cd to library folder
- git clone
- In your Di Manager call services:

```
   use Phalcon\Http\Response\Cookies;
   use Phalcon\Http\Response;
   use Phalcon\Http\Request;
   use Phalcon\Crypt;
  /*
   * Load Phalcon Crypt Service
   * \Phalcon\Crypt
   * @see https://docs.phalconphp.com/en/latest/reference/crypt.html
   * */
  $di->setShared('crypt', function(){
      $crypt = new Crypt();
      return $crypt;
  });

   /*
    * Load Phalcon Cookies Service
    * \Phalcon\Http\Response\Cookies
    * @see https://docs.phalconphp.com/en/latest/reference/cookies.html
    * */
    $di->setShared('cookies', function(){
        $cookies = new Cookies();
        $cookies->useEncryption(false);
        return $cookies;
    });

   /*
    * Load Phalcon Request Service
    * Phalcon\Http\Request
    * @see https://docs.phalconphp.com/en/latest/reference/request.html
     * */
    $di->setShared('request', function(){
       $request = new Request();
       return $request;
    });

   /*
    * Load gAuth Service
    * */
    $di->setShared('gauth', function(){
       $gauth = new gAuth();
        return $gauth;
    });
```

\###Creation Example:

```
   /*
    * Simple example via Router File
    * In this library we only use the Payload because
    * encryption is handled by Phalcon Crypt
    * */
    $app->get("/login", function(){

       /*
        * Method is called after success login.
        * @return string. Token is returned as HTTP response
        * */
        $this->gauth->createToken([
                'iss' => 'api.yourapp.com',
                'iat' => time(),
                'exp' => time() + 3600,
                'nbf' => date('Y-m-d H:m:j'),
                'sub' => [
                   'id' => 23, // after check
                    'role' => 'admin'
                    ]
                ]);

       /*
        * You need to call the store method if you want
        * to save the token as cookie.
        * @return void
        * */
        $this->gauth->store();

    });
```

\###Check Example

```
   /*
    * Token can be checked by calling isValid()
    * If any param doesn't match the condition the token will
    * be marked as invalid.
    * @see Manual Validations below
    * */
    $app->get("/private", function(){
        if(!$this->gauth->isValid()){
            throw new \Phalcon\Exception('Validation not passed');
        }
    });
```

### Manual Validations

[](#manual-validations)

```
    /*
     * Iss validation checks if the stored Iss
     * match with the current host by comparing
     * the current host $this->request->getHeader('host')
     * */
    if(!$this->gauth->validIss()){
        throw new \Phalcon\Exception('Iss not valid');
    }

    /*
     * Iat validation checks if the Issued at time
     * is not greater that current time.
     * */
    if(!$this->gauth->validIat()){
        throw new \Phalcon\Exception('Iat not valid' );
    }

    /*
     * Exp validation checks if current time is
     * greatter that stored time. If not then throw exception
     * */
    if(!$this->gauth->validExp()){
        throw new \Phalcon\Exception('Token was expired' );
    }

    /*
     * Nbf validation check if the creation date is
     * greatter that stored NBF. If not then throw exception
     * */
    if(!$this->gauth->validNbf()){
        throw new \Phalcon\Exception('Nbf cannot be greatter that token creation date' );
    }
```

\###Getters

```
    $app->get("/getters", function(){

        // Returns the stored hash
        $this->gauth->getStoredToken();

        // Returns the stored payload as Object
        $this->gauth->getObjectToken();

        // Returns the stored payload as JSON string
        $this->gauth->getJsonToken();

        // Returns token ISS as string
        $this->gauth->getIss();

        // Returns token IAT as string
        $this->gauth->getIat();

        // Returns token EXP as string
        $this->gauth->getExp();

        // Returns token NBF as string
        $this->gauth->getNbf();

        //Returns token SUB as array
        $this->gauth->getSub()

        //Returns SUB value by key
        $this->gauth->getSub('email')
        $this->gauth->getSub('id')

    });
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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.

### Community

Maintainers

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

---

Top Contributors

[![marcospaulosss](https://avatars.githubusercontent.com/u/21126521?v=4)](https://github.com/marcospaulosss "marcospaulosss (3 commits)")

### Embed Badge

![Health badge](/badges/marcospaulosss-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/marcospaulosss-jwt/health.svg)](https://phpackages.com/packages/marcospaulosss-jwt)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

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

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

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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