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

jwt 过期怎么刷新 #9

Open
WuJiY opened this issue Jan 24, 2018 · 4 comments
Open

jwt 过期怎么刷新 #9

WuJiY opened this issue Jan 24, 2018 · 4 comments

Comments

@WuJiY
Copy link

WuJiY commented Jan 24, 2018

过期怎么刷新

@czewail
Copy link
Owner

czewail commented Jan 25, 2018

新建refresh接口 解析传递过来的token后判断exp过期时间 并验证用户 通过后调用fromUser方法重新生成token返回就可以了
如果不做refresh过期时间判断,直接:

$user = JWT::authenticate();
return ApiResponse::array([
  'token' => JWT::fromUser($user)
]);

@osindex
Copy link

osindex commented Sep 28, 2018

然而 过期之后就无法获得用户信息。

$segments = explode('.', $token);
list(, $payload64) = $segments;
$payload = json_decode(\Zewail\Api\JWT\Library\UrlSafeBase64::decode($payload64), true, 512, JSON_BIGINT_AS_STRING);

@czewail
Copy link
Owner

czewail commented Sep 28, 2018

@osindex
token 包含了过期时间和用户信息等资料,是否过期需要自己判断,只要拿到了token就可以解析出用户名信息

@osindex
Copy link

osindex commented Sep 29, 2018

@czewail 嗯 我的意思就是 用贴出的方法自行获取~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants