-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTinywanJwtMethod.php
More file actions
43 lines (37 loc) · 1.1 KB
/
TinywanJwtMethod.php
File metadata and controls
43 lines (37 loc) · 1.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
38
39
40
41
42
43
<?php
namespace WebmanTech\Auth\Authentication\Method;
use InvalidArgumentException;
use Tinywan\Jwt\Exception\JwtTokenException;
use Tinywan\Jwt\JwtToken;
use WebmanTech\Auth\Interfaces\IdentityRepositoryInterface;
use WebmanTech\CommonUtils\Request;
/**
* tinywan/jwt 认证方式
* @link https://github.com/Tinywan/webman-jwt
*/
class TinywanJwtMethod extends BaseMethod
{
protected bool $throwException = false;
public function __construct(IdentityRepositoryInterface $identity, array $config = [])
{
parent::__construct($identity, $config);
if (!class_exists(\Tinywan\Jwt\JwtToken::class)) {
throw new InvalidArgumentException('请先安装 tinywan/jwt: composer require tinywan/jwt');
}
}
/**
* @inheritDoc
*/
protected function getCredentials(Request $request): ?string
{
try {
/** @phpstan-ignore-next-line */
return JwtToken::getCurrentId();
} catch (JwtTokenException $e) {
if ($this->throwException) {
throw $e;
}
return null;
}
}
}