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

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

dusta/jwt-ready
===============

Module jwt

v1.0.0(7y ago)2441[1 issues](https://github.com/dusta/jwt-ready/issues)MITPHP

Since Feb 2Pushed 7y ago1 watchersCompare

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

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

JWTReady
========

[](#jwtready)

Simple Firebase\\JWT wrapper

PHP Standalone
==============

[](#php-standalone)

```
use Dusta\JWTReady\JWTReady;

require_once __DIR__ . '/../vendor/autoload.php';
$JWTReady = new JWTReady(['key' => 'YOUR-SECRET-KEY']);

// Return string
$jwt = $JWTReady->generate(['key' => 'value']);
// return eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJrZXkiOm51bGwsImlhdCI6bnVsbC.....

// if empty check headers Bearer/s
$check = $JWTReady->checkJWT($jwt);
// return ['jwt' => 'eyJ0eXAiOiJKV1QiLCJhbG....', 'payload' => [...]]

$decoded = $JWTReady->decode($jwt);
// return ['key' => 'value']
```

Example SilmFramework
=====================

[](#example-silmframework)

**src/routers.php**

```
use Slim\Http\Request;
use Slim\Http\Response;

$app->get('/auth/check', function (Request $request, Response $response, array $args) {

    try {

        /** @var JWTReady $JWTReady */
        $JWTReady = $this->get('JWTReady');
        $checkJWT = $JWTReady->checkJWT();

    } catch (AuthorizationHeaderException $e) {
        return $response->withJson(['code' => 401, 'message' => 'Invalid BearerToken']);
    }

    return $response->withJson(['code' => 200])->withHeader('Bearer', $checkJWT->get('jwt'));
});
```

**src/dependencies.php**

```
use Dusta\JWTReady\JWTReady;

$container = $app->getContainer();

// monolog
$container['JWTReady'] = function ($c) {
    $settings = $c->get('settings')['JWTReady'];

    $JWTReady = new JWTReady($settings);
    return $JWTReady;
};
```

**src/settings.php**

```
