- WIP on header-based authentication
This commit is contained in:
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;
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user