1

OAuth 2 详解(五):Device Authorization Flow

 1 year ago
source link: https://jiajunhuang.com/articles/2022_10_11-oauth2_explained_device_code.md.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

OAuth 2 详解(五):Device Authorization Flow

我们经常可以看到这样的需求:智能电视要我们登录帐号,或者是命令行程序,需要登录帐号。提示通常都是:扫码或者打开网页 并且输入验证码后登录。这就是device authorization flow的流程了。

这个授权流程,定义在 RFC8628,我们来看看流程:

Device Authorization Flow
  1. 首先用户启动应用
  2. 应用携带 client_id, scope 请求 Authorization Server 的 /oauth/device/code 接口获取登录URL
  3. Authorization Server 返回 device_code, user_code, verification_url, verification_uri_complete, expires_in, interval
  4. 用户打开URL或者扫码访问,并且授权
  5. 应用按照服务器返回的轮询间隔,开始轮询 Authorization Server
  6. Authorization Server 判断用户是否已经同意授权
  7. 如果用户同意授权,则返回 access_token
  8. 应用使用 access_token 访问资源
  9. 服务器判断 access_token 是否有效,如果有效,返回对应资源

在什么地方会看到这种登录协议的使用场景呢?讲几个我看到的:

  1. 智能电视要求登录,用这种协议就很方便,把 verification_uri_complete 的内容展示在二维码中,用户扫码后,批准授权即可登录
  2. heroku cli 是这种流程
  3. aws cli 开启SSO登录之后,也是这种流程

其它的类似场景,也都可以使用这种流程来完成授权。


refs:


微信公众号
关注公众号,获得及时更新

Go设计模式:装饰器模式 程序员的MySQL手册(一): 安装,基本配置 ElasticSearch学习笔记 Go设计模式:composite模式 拯救删除ZFS之后的分区表 Linux使用redshift自动调整屏幕色温 Go设计模式:桥接模式和策略模式 Go设计模式:单例模式、原型模式和Builder模式 操作系统也是CRUD Go设计模式:简单工厂模式 把USB设备穿透给虚拟机里的系统 debug故事之:事务让生活更美好 Go设计模式:模板模式 Go设计模式:适配器模式 Go设计模式:Iterator



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK