Slim 3 with Json web Token

Hi Everybody,
im new to Slim, i need implement jwt with slim, i use this https://github.com/tuupola/slim-jwt-auth
in the backend is fine, i try with this code only for example :



use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php';

$app = new \Slim\App;
$app->add(new \Slim\Middleware\JwtAuthentication([
    "secret"=>"supersecretkeyyoushouldnotcommittogithub",
]));


$app->get('/hello/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();


the problem is when i call the api,i dont know how pass the jwt to the api, i try with autorization,
with header: “secret” “supersecretkeyyoushouldnotcommittogithub” but all return 401 not Unauthorized

What header have sent? According to the documentation, the expected header looks like:

Authentication: BEARER supersecretkeyyoushouldnotcommittogithub

yes i Try with uthentication: BEARER supersecretkeyyoushouldnotcommittogithub but dont work.

It seems you first need to make a call to fetch a token, then you can pass this token in the authentication header. There is an example Slim implementation that uses the slim-jwt-auth middleware at https://github.com/tuupola/slim-api-skeleton.

@robertfernan Could you solve it?

yes thanks for your help

1 Like

@robertfernan :wink: Any example available? Have you configure some extra?

I do not really remember but try this https://github.com/letsila/slim3-jwt-auth-example