简体   繁体   English

aws-amplify Auth.currentSession() 一小时后未提供刷新的令牌

[英]aws-amplify Auth.currentSession() not giving refreshed token after an hour

Which category is your question related to?您的问题与哪个类别有关?

AWS amplify auto handling refresh token AWS 放大自动处理刷新令牌

What AWS Services are you utilizing?您正在使用哪些 AWS 服务?

aws-amplify aws-放大

Provide additional details eg code snippets提供其他详细信息,例如代码片段

axios.interceptors.request.use(function(config) 
{ return Auth.currentSession() .then(session => { // User is logged in. 

  Set auth header on all requests 
  let accessToken = session.idToken.jwtToken; 

  axios.defaults.headers.common["Authorization"] = accessToken; 
  return Promise.resolve(config); })
   .catch(() => { 
  // No logged-in user: don't set auth header 
  return Promise.resolve(config); 
}); 
});

This is the interceptor request I'm using for now to get latest valid token irrespective of the total time, since user is logged-in as #446 and aws-amplify documentation tells that it is automatically refreshing token internally and Auth.currentSession() gives you the latest valid jwtToken every time.这是我现在使用的拦截器请求,无论总时间如何,都可以获取最新的有效令牌,因为用户以 #446 身份登录,并且 aws-amplify 文档告诉它会在内部自动刷新令牌和Auth.currentSession()每次都会为您提供最新的有效 jwtToken。

But what I experience is: I login: Auth.currentSession() keeps giving me the jwtToken that was received when logged_in.但我的经验是:我登录: Auth.currentSession()不断给我登录时收到的 jwtToken。 After an hour, the token was expired and Auth.currentSession() was still giving this previous expired token which caused my server to send me 401. How do I handle it?一个小时后,令牌已过期, Auth.currentSession()仍在提供之前过期的令牌,这导致我的服务器向我发送 401。我该如何处理? How do I keep getting latest valid refreshed jwtToken?如何不断获取最新的有效刷新 jwtToken? Am I using it wrong, or is it a bug?是我用错了还是bug?

This answer might be too late for you, but if anyone else stumbles on this thread, you are probably using 'token' as your Authorization grant flow.这个答案对您来说可能为时已晚,但如果其他人偶然发现此线程,则您可能正在使用“令牌”作为您的授权授予流程。 Use 'code' instead.改用“代码”。 Dont forget to change that in cognito console as well.不要忘记在 cognito 控制台中更改它。 Select Authorization Code grant instead of implicit grant选择授权代码授权而不是隐式授权

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM