aboutsummaryrefslogtreecommitdiff
path: root/middlewares/TokenAuthenticationMiddleware.php
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2025-01-03 06:19:24 +0100
committerGravatar GitHub <noreply@github.com> 2025-01-03 06:19:24 +0100
commit3fc38c15a3afa7e0377e3b6cb4ffec1335a36f63 (patch)
treea03f4349bfb87a36648cca723fbffcbba091c34f /middlewares/TokenAuthenticationMiddleware.php
parentbe51ba17df892fde0c371c181425dd636f0f4d37 (diff)
downloadrss-bridge-3fc38c15a3afa7e0377e3b6cb4ffec1335a36f63.tar.gz
rss-bridge-3fc38c15a3afa7e0377e3b6cb4ffec1335a36f63.tar.zst
rss-bridge-3fc38c15a3afa7e0377e3b6cb4ffec1335a36f63.zip
fix: cache 400 and 404, and refactor token auth (#4388)
* fix(cache): also cache 400 and 404 responses * refactor(token_auth)
Diffstat (limited to 'middlewares/TokenAuthenticationMiddleware.php')
-rw-r--r--middlewares/TokenAuthenticationMiddleware.php16
1 files changed, 10 insertions, 6 deletions
diff --git a/middlewares/TokenAuthenticationMiddleware.php b/middlewares/TokenAuthenticationMiddleware.php
index f8234629..31544ab7 100644
--- a/middlewares/TokenAuthenticationMiddleware.php
+++ b/middlewares/TokenAuthenticationMiddleware.php
@@ -10,20 +10,24 @@ class TokenAuthenticationMiddleware implements Middleware
return $next($request);
}
- // Always add token to request attribute
- $request = $request->withAttribute('token', $request->get('token'));
+ $token = $request->get('token');
- if (! $request->attribute('token')) {
+ if (! $token) {
return new Response(render(__DIR__ . '/../templates/token.html.php', [
- 'message' => 'Missing token',
+ 'message' => 'Missing token',
+ 'token' => '',
]), 401);
}
- if (! hash_equals(Configuration::getConfig('authentication', 'token'), $request->attribute('token'))) {
+
+ if (! hash_equals(Configuration::getConfig('authentication', 'token'), $token)) {
return new Response(render(__DIR__ . '/../templates/token.html.php', [
- 'message' => 'Invalid token',
+ 'message' => 'Invalid token',
+ 'token' => $token,
]), 401);
}
+ $request = $request->withAttribute('token', $token);
+
return $next($request);
}
}