Protect endpoints using JWT tokens for authentication
Register the service provider in the bootstrap/app.php
$app->register(ToeFungi\Token\Laravel\Providers\TokenServiceProvider::class);
Register the middleware authentication layer in the bootstrap/app.php
$app->routeMiddleware([
'auth' => ToeFungi\Token\Laravel\Middleware\TokenAuthentication::class,
]);
Example of an endpoint that is protected. Ensure it uses the auth
middleware layer
$app->get('/protected', [
'middleware' => 'auth',
'uses' => 'Controller@protectedEndpoint'
]);
Remember to set all of the below
TOKEN_ISS='http://youdomain.co.za'
TOKEN_AUDIENCE='http://yourdomain.co.za'
TOKEN_LIFESPAN=3600
TOKEN_PRIV_KEY=(RSA Key)
TOKEN_PUB_KEY=(RSA Key)