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