PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] Slim Framework : unable to use JWT token

 March 07, 2022     authentication, composer-php, jwt, php, slim     No comments   

Issue

I am working on a slim REST API and I want to secure it with JWT Token. I try a lot of tutorials and I am anable to make things work.

I use :
slim 4.*
slim/psr7 0.6.0
tuupola/slim-jwt-auth ^3.4
tuupola/cors-middleware ^1.1

Ubuntu 19.10 and Xampp

I have have 2 routes (POST /login and GET /api/test)
I want to be able to use the /login route without token and the other one with a token. So I wrote :

$app->add(new Tuupola\Middleware\JwtAuthentication([
    "path" => "/api",
    "secret" => getenv ("SPROUTCH_TOKEN"),
    "error" => function ($request, $response, $arguments) {
        $data["status"] = "error";
        $data["message"] = $arguments["message"];
        return $response
            ->withHeader("Content-Type", "application/json")
            ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
    },
]));

In that case nothing is secure so I tried this :

$app->add(new Tuupola\Middleware\JwtAuthentication([
    "secret" => getenv ("SPROUTCH_TOKEN"),
    "error" => function ($request, $response, $arguments) {
        $data["status"] = "error";
        $data["message"] = $arguments["message"];
        return $response
            ->withHeader("Content-Type", "application/json")
            ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
    },
]));

And of course I can't access anything.


Solution

The proble was just that the "path" key takes only absolute path



Answered By - Anthony Quéré
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing