Slim 3 with Json web Token


#1

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


#2

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

Authentication: BEARER supersecretkeyyoushouldnotcommittogithub

#3

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


#4

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.


#5

@robertfernan Could you solve it?


#6

yes thanks for your help


#7

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


#8

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