Skip to content

Commit b5d9dc1

Browse files
committed
feat: #19 增加GET方式获取令牌,有的项目并不是从header里
1 parent cae640a commit b5d9dc1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/JwtToken.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,15 @@ private static function getTokenFromHeaders(): string
219219
{
220220
$authorization = request()->header('authorization');
221221
if (!$authorization || 'undefined' == $authorization) {
222-
throw new JwtTokenException('请求未携带authorization信息');
222+
$config = self::_getConfig();
223+
if (!isset($config['is_support_get_token']) || false === $config['is_support_get_token']) {
224+
throw new JwtTokenException('请求未携带authorization信息');
225+
}
226+
$authorization = request()->get($config['is_support_get_token_key']);
227+
if (empty($authorization)) {
228+
throw new JwtTokenException('请求未携带authorization信息');
229+
}
230+
$authorization = 'Bearer '.$authorization;
223231
}
224232

225233
if (self::REFRESH_TOKEN != substr_count($authorization, '.')) {

src/config/plugin/tinywan/jwt/app.php

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
return [];
4848
},
4949

50+
/** 是否支持 get 请求获取令牌 */
51+
'is_support_get_token' => true,
52+
/** GET 请求获取令牌请求key */
53+
'is_support_get_token_key' => 'authorization',
54+
5055
/** access令牌私钥 */
5156
'access_private_key' => <<<EOD
5257
-----BEGIN RSA PRIVATE KEY-----

0 commit comments

Comments
 (0)