Added SharedSecretBasicAuthenticationMiddleware
This commit is contained in:
41
src/SharedSecretBasicAuthenticationMiddleware.php
Normal file
41
src/SharedSecretBasicAuthenticationMiddleware.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
namespace CloudObjects\SDK\Laravel;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use CloudObjects\SDK\Helpers\SharedSecretAuthentication;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
class SharedSecretBasicAuthenticationMiddleware {
|
||||||
|
|
||||||
|
private $authenticationHelper;
|
||||||
|
|
||||||
|
public function __construct(SharedSecretAuthentication $authenticationHelper)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user