SessionAuthBackend::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Koded\Framework\Auth;
4
5
use function Koded\Session\session;
6
use function password_hash;
7
8
/**
9
 * A basic authentication storage that uses the
10
 * PHP session for the user object.
11
 *
12
 * The format of the credentials session key is:
13
 *
14
 *  `<type>.<password_hash(credentials)>`
15
 *
16
 * Example: Bearer.a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
17
 * Example: Token.$2y$10$FRmWYon7sMY4lZKW2D3NZueT3iUAsQj.MjfOSbukrBpLI9Qce11JO
18
 */
19
class SessionAuthBackend implements AuthBackend
20
{
21
    public function __invoke(string $type, string $credentials): ?object
22
    {
23
        return session()->get($type . '.' . password_hash($credentials, PASSWORD_DEFAULT));
24
    }
25
}
26