-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViaStorage.php
More file actions
37 lines (31 loc) · 1 KB
/
ViaStorage.php
File metadata and controls
37 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types = 1);
namespace Innmind\HttpAuthentication;
use Innmind\HttpAuthentication\ViaStorage\Storage;
use Innmind\Http\ServerRequest;
use Innmind\Immutable\Attempt;
final class ViaStorage implements Authenticator
{
private Authenticator $authenticate;
private Storage $storage;
public function __construct(Authenticator $authenticate, Storage $storage)
{
$this->authenticate = $authenticate;
$this->storage = $storage;
}
public function __invoke(ServerRequest $request): Attempt
{
return $this
->storage
->get($request)
->attempt(static fn() => new \RuntimeException('Identity not in storage'))
->recover(
fn() => ($this->authenticate)($request)->map(
function($identity) use ($request) {
$this->storage->set($request, $identity);
return $identity;
},
),
);
}
}