branca-middleware
branca-middleware copied to clipboard
Ability to specify TTL per path?
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.
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);
Huh. Sounds like a plan thanks!