- WIP on header-based authentication

This commit is contained in:
mcndave committed 2023-11-03 08:26:48 -04:00
1 parent ad802fc35d
commit 944c524cfb
8 files changed
+143 -1

No files matched your search

@@ -0,0 +1,11 @@
<?php
namespace Ulmus\User\Authorize;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\User\Entity\UserInterface;
interface AuthorizeMethodInterface
{
public function connect(ServerRequestInterface $request) : UserInterface|false;
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Ulmus\User\Authorize;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\User\Entity\UserInterface;
class BasicAuthentication implements AuthorizeMethodInterface
{
public function connect(ServerRequestInterface $request): UserInterface|false
{
if ( null === $auth = $request->getHeader('Authorization') ) {
list($method, $userPass) = explode(' ', $auth, 2) + [ null, null ];
if (! $method ) {
throw new \InvalidArgumentException("An authentication method must be provided");
}
elseif (! $userPass ) {
throw new \InvalidArgumentException("A base64-encoded 'user:password' value must be provided");
}
return false;
}
return false;
}
protected function basicMethod(string $header) : UserInterface|false
{
}
}