Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中间件中处理前台请求的token,一直获取失败 #7

Closed
canren opened this issue Jan 28, 2021 · 2 comments
Closed

中间件中处理前台请求的token,一直获取失败 #7

canren opened this issue Jan 28, 2021 · 2 comments

Comments

@canren
Copy link
Contributor

canren commented Jan 28, 2021

hyperf-ext/jwt 版本 2.0.* 升级到 2.1.*
hyperf-ext/auth 版本 2.0.* 升级到 2.1.*

代码升级中发现一个问题,执行测试用例 header 头中携带的 Authorization 是正确的,但是中间键一直在抛出异常 HyperfExt\Jwt\Exceptions\JwtException: Token could not be parsed from the request.(0),代码追踪到 src/Jwt.php:line 164 发现用了协程重写

    /**
     * Get the token.
     */
    public function getToken(): ?Token
    {
        if (empty($token = Context::get(Token::class))) {
            try {
                $this->parseToken();
                // 解析请求中的令牌,这边放在协程里面了,没有取出来,是否存在问题?
                // $token = Context::get(Token::class);
            } catch (JwtException $e) {
                $token = null;
            }
        }
        return $token;
    } 

我先在处理的方案是在中间件中预先调用了一下,解析请求中的令牌

    $this->auth->guard()->parseToken();
    $this->auth->guard()->user();
@ericyzhu
Copy link
Member

这是一个尴尬的问题……已经修复了,确实忘记再次取值了

@canren
Copy link
Contributor Author

canren commented Jan 29, 2021

谢谢

@canren canren closed this as completed Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants