From 90cd7765b253c07aa55d5276d1a4f5e015258f04 Mon Sep 17 00:00:00 2001 From: LukasRos Date: Tue, 17 Sep 2024 22:55:24 +0200 Subject: [PATCH] Added SharedSecretBasicAuthenticationMiddleware --- ...redSecretBasicAuthenticationMiddleware.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/SharedSecretBasicAuthenticationMiddleware.php diff --git a/src/SharedSecretBasicAuthenticationMiddleware.php b/src/SharedSecretBasicAuthenticationMiddleware.php new file mode 100644 index 0000000..3b8e389 --- /dev/null +++ b/src/SharedSecretBasicAuthenticationMiddleware.php @@ -0,0 +1,41 @@ +authenticationHelper = $authenticationHelper; + } + + /** + * Handle an incoming request. + * + * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + */ + public function handle(Request $request, Closure $next): Response + { + if ($this->authenticationHelper->verify( + $request->getUser(), $request->getPassword() + ) == SharedSecretAuthentication::RESULT_OK) { + // Credentials have been validated + return $next($request); + } + + // Fail with 401 if not + App::abort(401); + } +} \ No newline at end of file