https://github.com/dusta/jwt-ready
Simple Firebase\JWT wrapper
https://github.com/dusta/jwt-ready
auth authentication dframe firebase jwt slim standalone wrapper
Last synced: about 2 months ago
JSON representation
Simple Firebase\JWT wrapper
- Host: GitHub
- URL: https://github.com/dusta/jwt-ready
- Owner: dusta
- License: mit
- Created: 2019-02-02T13:29:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-02T17:37:55.000Z (over 7 years ago)
- Last Synced: 2026-04-03T23:09:12.735Z (3 months ago)
- Topics: auth, authentication, dframe, firebase, jwt, slim, standalone, wrapper
- Language: PHP
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWTReady
Simple Firebase\JWT wrapper
# PHP Standalone
```php
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
**src/routers.php**
```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**
``` 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**
```php
[
'displayErrorDetails' => true, // set to false in production
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
'JWTReady' => [
'key' => 'SecretKey',
'iat' => null,
'jti' => null,
'iss' => null,
'nbf' => null,
'exp' => null,
'data' => null
]
],
];
```