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

Refresh token fail. #2136

Open
uax opened this issue Jul 2, 2021 · 0 comments
Open

Refresh token fail. #2136

uax opened this issue Jul 2, 2021 · 0 comments

Comments

@uax
Copy link

uax commented Jul 2, 2021

Subject of the issue

Describe your issue here.

Your environment

Q A
Bug? no
New Feature? no
Framework Laravel / Swoole
Framework version 6.x.y
Package version 1.x.y
PHP version 5.x.y / 7.x.y

use jwt-auth in php cli with Swoole.

Swoole:https://www.swoole.co.uk/docs/modules/swoole-websocket-server
The code is running under php artisan command, and websocket is turned on.
When the token expired, I refreshed the front page for the first time, the result was normal, and I got the refresh token. Save the refresh token to the localstore.
Wait for 1 minute to make sure that the token has expired, and refresh the page for the second time, at this time there is no refresh token.

public function handle()
    {
        $ws = new Server('0.0.0.0', 9501);

        $ws->on('open', function (Server $ws, $request) {
            echo "server: handshake success with fd{$request->fd}\n";
        });

        $ws->on('message', function (Server $ws, $frame) {
            echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
            try {
                JWTAuth::setToken($frame->data->token);
                $user = JWTAuth::authenticate();
            } catch (TokenExpiredException $e) {
                $this->info('Refresh:'.$e->getMessage());
                $refresh_token = JWTAuth::refresh();
                JWTAuth::setToken($msg->data);
                $user = JWTAuth::authenticate();
            } catch (TokenInvalidException $e) {
                // relogin
                $this->info('Relogin:'.$e->getMessage());
            } catch (JWTException $e) {
                $this->info('Relogin:'.$e->getMessage());
            }
        });

        $ws->on('close', function ($ser, $fd) {
            echo "client {$fd} closed\n";
        });

        $ws->start();
    }

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

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

1 participant