slim-jwt-auth icon indicating copy to clipboard operation
slim-jwt-auth copied to clipboard

Path option for case insensitive

Open UnbrandedTech opened this issue 8 years ago • 2 comments

Slim has an option to make routes case sensitive or not. I turned this feature on and it took me awhile to figure out why the JWT token wasn't in $app.

$app->config([ 'routes.case_sensitive' => false ]);

I suggest adding a 'path_case_sensitive' option to the options array.

If you'd like a PR I can send it your way.

UnbrandedTech avatar Nov 17 '15 06:11 UnbrandedTech

Can you show example code which describes the problem.

tuupola avatar Nov 17 '15 07:11 tuupola

Sure.

Here's my route

$app->get('/doc', 'Class:function');

In my index, I have

$app = new \Slim\Slim();
$app->config([ 'routes.case_sensitive' => false ]);
$app->registeredEndpoints = ["/doc"];
$app->add(new \Slim\Middleware\JwtAuthentication([
    "path" => $app->registeredEndpoints,
    "secret" => ACCESS_KEY,
    "callback" => function ($options) use ($app) {
            $app->jwt = $options["decoded"];
    },
    "relaxed" => ["localhost"],
]));

$app->hook("slim.before.router", function() use ($app){
    $path = $app->request()->getPathInfo();
    $endpoints = $app->registeredEndpoints;
    $found = false;
    foreach($endpoints as $endpoint){
               $endpoint = strtolower($endpoint);
        if (strpos($path, $endpoint) === 0) {
            $found = true;
            require_once("Routes{$endpoint}.php");
            break;
        }
    }
});

$app->run();

So when I make a request to http://localhost/Doc

Slim picks it up and routes it correctly and my lazy loader includes the routes correctly but because the function in your middleware doesn't match the path that I set the JWT callback never gets called and the token isn't in the slim instance.

UnbrandedTech avatar Nov 20 '15 03:11 UnbrandedTech