PHPackages                             steffenbrand/non-static-php-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. steffenbrand/non-static-php-jwt

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

steffenbrand/non-static-php-jwt
===============================

non-static wrapper for php-jwt

v5.0.0(7y ago)119.0kPHPPHP &gt;=7.1

Since Aug 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/steffenbrand/non-static-php-jwt)[ Packagist](https://packagist.org/packages/steffenbrand/non-static-php-jwt)[ Docs](https://github.com/steffenbrand/non-static-php-jwt)[ RSS](/packages/steffenbrand-non-static-php-jwt/feed)WikiDiscussions master Synced 3d ago

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

non-static-php-jwt
==================

[](#non-static-php-jwt)

non-static-php-jwt is a wrapper for [firebase/php-jwt](https://github.com/firebase/php-jwt) to make it easily mockable with [phpspec/prophecy](https://github.com/phpspec/prophecy) (or any other mocking library) within your phpunit tests.

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

[](#installation)

```
composer require steffenbrand/non-static-php-jwt

```

Versioning
----------

[](#versioning)

The releases will match the release versions of [firebase/php-jwt](https://github.com/firebase/php-jwt) starting with ^5.0.
The supported PHP versions will be ^7.1, since return types and type hinting are used in this library.

Usage
-----

[](#usage)

It's just a wrapper for [firebase/php-jwt](https://github.com/firebase/php-jwt), so the usage is almost the same, except the fact that you have to create an instance of `\SteffenBrand\NonStaticPhpJwt\Jwt` first.

### Encoding and decoding

[](#encoding-and-decoding)

```
$jwt = new \SteffenBrand\NonStaticPhpJwt\Jwt();

$key = 'example_key';
$token = [
    'iss' => 'http://example.org',
    'aud' => 'http://example.com',
    'iat' => 1356999524,
    'nbf' => 1357000000
];

$webToken = $jwt->encode($token, $key);
$decoded = $jwt->decode($webToken, $key, ['HS256']);

var_dump($decoded);
print_r((array) $decoded);
```

### Adding a leeway

[](#adding-a-leeway)

You can add a leeway to account for when there is a clock skew times between the signing and verifying servers. It is recommended that this leeway should not be bigger than a few minutes.

Source:

The leeway if the fourth parameter of the decode method and defaults to `0`.

```
$jwt->decode($jwt, $key, ['HS256'], $leeway = 60);
```

### Prophecising

[](#prophecising)

The primary goal of this library is to allow prophecising the results of JWT methods within you phpunit tests.

```
