Skip to content

Commit 7f9e98a

Browse files
authored
Update README.md
1 parent ee5b97c commit 7f9e98a

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $ php think jwt:make
2121
* `notBefore` 时间前不能使用 默认生成后直接使用
2222
* `expiresAt` Token有效期(秒)
2323
* `signer` 加密算法
24+
* `type` 获取 Token 途径
2425
* `injectUser` 是否注入用户模型
2526
* `userModel` 用户模型
2627
* `hasLogged` 开启单点登录时,多点登录抛异常code = 50401
@@ -93,3 +94,58 @@ class UserController {
9394
}
9495

9596
```
97+
98+
6. 自动获取验证
99+
100+
支持以下方式自动获取
101+
102+
* `Bearer`
103+
* `Cookie`
104+
* `Url`
105+
106+
赋值方式
107+
108+
类型 | 途径 | 标识 |
109+
:-: | :-: | :-: |
110+
Header | Authorization | Bearer |
111+
Cookie | Cookie| token |
112+
Url | Request | token |
113+
114+
```php
115+
# config/jwt.php
116+
117+
<?php
118+
119+
return [
120+
121+
// ...其它配置
122+
'type' => 'Header',
123+
124+
// 'type' => 'Cookie',
125+
// 'type' => 'Url',
126+
];
127+
```
128+
129+
```php
130+
# UserController.php
131+
132+
use xiaodi\Facade\Jwt;
133+
134+
class User
135+
{
136+
public function index()
137+
{
138+
// 自动获取并验证
139+
try {
140+
Jwt::verify();
141+
} catch (HasLoggedException $e) {
142+
// 已在其它终端登录
143+
} catch (TokenAlreadyEexpired $e) {
144+
// Token已过期
145+
}
146+
147+
$uid = Jwt::userId();
148+
}
149+
150+
}
151+
```

0 commit comments

Comments
 (0)