【发布时间】:2018-12-09 18:13:48
【问题描述】:
我正在使用 AWS Cognito 作为 android 应用程序的 mu 身份验证提供程序,并且我在我的用户池中设置了 30 天的刷新令牌过期时间。
我收到的访问令牌有效期最长为 1 小时,因此如果用户离开应用并在 1 小时内返回,我可以通过在 CognitoUserPool 上调用 getCurrentUser() 自动更新用户会话。
但是,如果用户在几个小时后回来,我想使用缓存的刷新令牌,这样他们就不需要经常重新登录。CognitoUserPool 文档表明它只会在使用刷新令牌时使用而访问令牌仍处于活动状态。
这不会破坏刷新令牌的目的,还是说刷新令牌只能在访问令牌处于活动状态时使用?
如果无法使用刷新令牌来获取新会话,应用如何让用户一次保持一天/数周/数月的登录状态?他们是否将密码存储在设备上?
【问题讨论】:
-
您在哪里看到“只有在访问令牌仍然处于活动状态时才使用刷新令牌”的部分?这似乎与docs.aws.amazon.com/cognito/latest/developerguide/… 冲突
-
@Michael-sqlbot 身份验证失败的原因是因为我使用的是
getSession而不是getSessionInBackground,并且由于它在主线程上运行而引发了异常。 -
但是,我似乎误解的部分文档是
The Mobile SDK for iOS and the Mobile SDK for Android automatically refresh your ID and access tokens if there is a valid (non-expired) refresh token present, and the ID and access tokens have a minimum remaining validity of 5 minutes. If the refresh token is expired, your app user must reauthenticate by signing in again to your user pool.说访问令牌必须至少再有效 5 分钟才能刷新。 -
我可能不正确,但我将其解释为,当用户处于活动状态时,访问和令牌持续保持最新状态,并且每次接近到期时,SDK在令牌达到其剩余不到 5 分钟的有效期之前开始处理此后台自动刷新。
标签: android amazon-web-services security authentication aws-cognito