- WIP on 2.x auth. method
This commit is contained in:
1 parent
23079e6040
commit
6582378b6e
5 files changed
+70
-9
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\User\Middleware;
|
||||
|
||||
use Psr\Http\{
|
||||
Message\ResponseInterface,
|
||||
Message\ServerRequestInterface,
|
||||
Server\MiddlewareInterface,
|
||||
Server\RequestHandlerInterface
|
||||
};
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
use Ulmus\User\Authorize\PostRequestAuthentication;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
use Ulmus\User\Lib\AuthenticationMethodEnum;
|
||||
|
||||
class AuthenticationMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected UserInterface $user,
|
||||
protected Authenticate $authenticator,
|
||||
) {}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
if (null !== $id = $request->getAttribute('authentication_middleware:user_id')) {
|
||||
$this->authenticator->loadUser($id);
|
||||
}
|
||||
|
||||
switch($request->getAttribute('authentication_middleware:method')) {
|
||||
case AuthenticationMethodEnum::ForceLogin:
|
||||
$this->authenticator->login();
|
||||
break;
|
||||
|
||||
case AuthenticationMethodEnum::UsernamePassword:
|
||||
$this->authenticator->authenticate($request->getAttribute('authentication_middleware:username'), $request->getAttribute('authentication_middleware:password'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user