Skip to content

Commit d6d68e9

Browse files
authored
header授权字段名可配置
现在项目中的名字是固定大写开头的,很多情况下vue前端会把请求头信息全部转换成小写,或者有些项目不是用的Authorization,就无法使用,为了这个名字而自定义Guard的话又比较麻烦,所以做成配置项比较合理。
1 parent 4ac974e commit d6d68e9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Guard/JwtGuard.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class JwtGuard extends AbstractAuthGuard
3333
*/
3434
protected $request;
3535

36+
protected $headerName = 'Authorization';
37+
3638
/**
3739
* JwtGuardAbstract constructor.
3840
*/
@@ -43,13 +45,14 @@ public function __construct(
4345
RequestInterface $request
4446
) {
4547
parent::__construct($config, $name, $userProvider);
48+
$this->headerName = $config['header_name'] ?? 'Authorization';
4649
$this->jwtManager = new JWTManager($config);
4750
$this->request = $request;
4851
}
4952

5053
public function parseToken()
5154
{
52-
$header = $this->request->header('Authorization', '');
55+
$header = $this->request->header($this->headerName, '');
5356
if (Str::startsWith($header, 'Bearer ')) {
5457
return Str::substr($header, 7);
5558
}

0 commit comments

Comments
 (0)