- WIP on authentication

This commit is contained in:
mcndave committed 2023-11-09 13:38:07 -05:00
1 parent 9ae3e2d6f9
commit 0f2886b266
6 files changed
+189 -30

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Ulmus\User\Authorize\Header;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authorize;
class BasicMethod
{
public function __construct(
protected UserInterface $user,
protected string|array $arguments
) {}
public function execute(ServerRequestInterface $request) : bool
{
if ( false === $decoded = base64_decode($this->arguments) ) {
throw new \RuntimeException("Base64 decoding of given username:password failed");
}
list($userName, $password) = explode(':', $decoded) + [ null, null ];
if ( empty($userName) ) {
throw new \RuntimeException("A username must be provided");
}
elseif ( empty($password) ) {
throw new \RuntimeException("A password must be provided");
}
( new Authorize($this->user) )->authenticate([ 'email' => $userName, 'username' => $userName ], $password);
return $this->user->loggedIn();
}
}