为什么访问令牌会过期? [英] Why do access tokens expire?

查看:25
本文介绍了为什么访问令牌会过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Google API 和 OAuth2.当客户授权我的应用程序时,我会得到一个刷新令牌"和一个短暂的访问令牌".现在每次访问令牌过期时,我都可以将我的刷新令牌发布给 Google,他们会给我一个新的访问令牌.

I am just getting started working with Google API and OAuth2. When the client authorizes my app I am given a "refresh token" and a short lived "access token". Now every time the access token expires, I can POST my refresh token to Google and they will give me a new access token.

我的问题是访问令牌到期的目的是什么?为什么不能有一个持久的访问令牌而不是刷新令牌?

My question is what is the purpose of the access token expiring? Why can't there just be a long lasting access token instead of the refresh token?

另外,刷新令牌会过期吗?

Also, does the refresh token expire?

有关 Google OAuth2 工作流程的更多信息,请参阅使用 OAuth 2.0 访问 Google API.

See Using OAuth 2.0 to Access Google APIs for more info on Google OAuth2 workflow.

推荐答案

这在很大程度上是特定于实现的,但总体思路是允许提供者发布短期访问令牌和长期刷新令牌.为什么?

This is very much implementation specific, but the general idea is to allow providers to issue short term access tokens with long term refresh tokens. Why?

  • 许多提供商支持安全性非常弱的不记名令牌.通过使它们短暂存在并需要刷新,它们可以限制攻击者滥用被盗令牌的时间.
  • 大规模部署不想在每次 API 调用时都执行数据库查找,因此他们会发布可通过解密进行验证的自编码访问令牌.但是,这也意味着无法撤销这些令牌,因此它们的发行时间很短,必须刷新.
  • 刷新令牌需要客户端身份验证,这使得它更强大.与上述访问令牌不同,它通常通过数据库查找来实现.

这篇关于为什么访问令牌会过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆