简体   繁体   English

如何检查身份验证令牌是否已过期并强制注销?

[英]How to check if auth token is expired and force logout?

I am using auth0 for my client-side user authentication and authorization.我使用 auth0 进行客户端用户身份验证和授权。 This is the flow`这是流量`

const authService = new auth0.WebAuth(coreConstants.AUTH0_OPTIONS);
const currentDate = Date.now();

authService.parseHash((err, authResult) => {
    if(err) console.log(err)
    const idToken = authResult.idToken;
    window.localStorage.setItem('auth', JSON.stringify({
                            expiresAt: someDate + Date.now()
                            accessToken: authResult.accessToken,
                            idToken,
                        }));
})

My problem now is that when the token is expired the user yet can interact with the page and just refreshing the page redirects the user to the login page.我现在的问题是,当令牌过期时,用户还可以与页面交互,只需刷新页面即可将用户重定向到登录页面。 I have already read auth0 documentation but couldn't find an appropriate solution for checking if the token is expired.我已经阅读了auth0文档,但找不到合适的解决方案来检查令牌是否已过期。 Any bits of advice?有什么建议吗?

Did you try jwt.verify ?你试过jwt.verify吗? it will check if the token is expired.它将检查令牌是否已过期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果令牌过期则注销 - Logout if token is expired 使用过期的 JWT 令牌注销用户 - Logout user on expired JWT token ReactJS:如何不断检查本地存储中的令牌是否已过期? - ReactJS: How to constantly check if token in localstorage has expired? 访问令牌过期时如何在带有 keycloak 的 Nuxt auth 模块(oauth2)中使用刷新令牌 - How to use refresh token in Nuxt auth module (oauth2) with keycloak when access token expired Firebase:错误(授权/用户令牌过期) - Firebase: Error (auth/user-token-expired) 如何检查令牌过期和注销用户? - How do I check for token expiration and logout user? 如何将AWS的ID令牌和访问令牌作为cookie传递,并检查它们是否已过期? - How to pass the ID Token and Access Token from AWS as cookies and check if they are expired? 使用此 JWT 库检查令牌是否过期 - Check if token expired using this JWT library 使用JavaScript,如何检查Auth0无密码会话已到期 - Using JavaScript, how do I check that an Auth0 passwordless session has expired 使用javascript的Google Oauth跨客户端身份验证:令牌已过期 - Google Oauth Cross-client auth with javascript: Token has expired
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM