branca-middleware icon indicating copy to clipboard operation
branca-middleware copied to clipboard

Ability to specify TTL per path?

Open Tsaukpaetra opened this issue 2 years ago • 2 comments

I was pondering on how to make this middleware apply the ttl parameter differently depending on which path was provided. Is the best way to do this by leaving the library's ttl option null and instead adding a before callable which re-decodes the token to extract the timestamp?

I was thinking if it would be feasible to run through an array of callables if the ttl option was specified like that in a similar manner to the rules, but I'm not sure how effective that would be either.

Tsaukpaetra avatar Oct 25 '22 04:10 Tsaukpaetra

Some frameworks allow you to attach middleware to specific routes or routegroups. So you could create two (or more) instances of the middleware with different ttl settings and then attachs these to different routes.

With Slim it would be something like:

$mw1 = new Tuupola\Middleware\BrancaAuthentication([
    "ttl" => 60, /* 60 seconds */
]);

$mw2 = new Tuupola\Middleware\BrancaAuthentication([
    "ttl" => 3600, /* 60 minutes */
]);

...

$app->get("/foo", function () { ... })->add($mw1);
$app->get("/bar", function () { ... })->add($mw2);

tuupola avatar Oct 25 '22 10:10 tuupola

Huh. Sounds like a plan thanks!

Tsaukpaetra avatar Oct 26 '22 04:10 Tsaukpaetra