Silex JWT
Library for work with JWT on Silex framework., (*1)
You can generate and check JWT tokens, use middleware for auth checking., (*2)
Installation
composer require ofat\silex-jwt, (*3)
Usage
- Register service provider:
```php
<?php, (*4)
use Ofat\SilexJWT\JWTAuth;
use Silex\Application;, (*5)
//Start our application
$app = new Silex\Application();, (*6)
//Register silex jwt service provider. Add jwt secret key
$app->register(new JWTAuth(),[
'jwt.secret' => 'test'
]);, (*7)
//Example of jwt generating
$app->post('/login', function(Request $request) use ($app) {
$userId = 1;
$token = $app['jwt_auth']->generateToken($userId);, (*8)
return $app->json(['token' => $token]);
});, (*9)
//Example of checking json web token
$app->get('/test', function(Request $request) use ($app) {
return $app->json(['test' => true]);
})->before(new JWTTokenCheck());
`, (*10)