跳到主要内容

1. 引言 (Introduction)

此 OAuth 2.0 [RFC6749] protocol extension 允许 OAuth client 从输入能力受限或缺少合适 browser 的 device 上的 application 请求 user authorization. 这类 device 包括 smart TV, media console, picture frame 和 printer, 它们缺少 traditional OAuth interaction 所需的便捷输入方式或合适 browser. 本规范定义的 authorization flow 有时称为 "device flow", 它指示 user 在 secondary device 上审查 authorization request, 例如在具备完成 user interaction 所需输入和 browser 能力的 smartphone 上完成.

device authorization grant 并不旨在取代 smartphone 等有能力 device 上 native app 中基于 browser 的 OAuth. 这些 app 应遵循 "OAuth 2.0 for Native Apps" [RFC8252] 中指定的实践.

使用此 authorization grant type 的运行要求如下:

  1. device 已经连接到 Internet.
  2. device 能够发出 outbound HTTPS request.
  3. device 能够向 user 显示或以其他方式传达 URI 和 code sequence.
  4. user 拥有可处理 request 的 secondary device, 例如 personal computer 或 smartphone.

由于 device authorization grant 不要求 device 上的 OAuth client 与 user agent 之间进行双向通信, 这不同于 authorization code 和 implicit grant type 等其他 OAuth 2 grant type, 因此它支持若干无法由这些其他方式服务的用例.

device client 不直接与 end user's user agent, 即 browser, 交互, 而是指示 end user 使用另一台 computer 或 device, 并连接到 authorization server 以批准 access request. 由于该 protocol 支持无法接收入站 request 的 client, client 会重复 poll authorization server, 直到 end user 完成 approval process.

device client 通常会选择要支持的一组 authorization server, 即它自己的 authorization server 或与其有关系的 provider 的 authorization server. device client 通常只支持一个 authorization server, 例如某个特定 media provider 的 TV application 只支持该 provider 的 authorization server. user 可能尚未与该 authorization provider 建立关系, 但可以在 authorization flow 期间建立这种关系.

     +----------+                                +----------------+
| |>---(A)-- Client Identifier --->| |
| | | |
| |<---(B)-- Device Code, ---<| |
| | User Code, | |
| Device | & Verification URI | |
| Client | | |
| | [polling] | |
| |>---(E)-- Device Code --->| |
| | & Client Identifier | |
| | | Authorization |
| |<---(F)-- Access Token ---<| Server |
+----------+ (& Optional Refresh Token) | |
v | |
: | |
(C) User Code & Verification URI | |
: | |
v | |
+----------+ | |
| End User | | |
| at |<---(D)-- End user reviews --->| |
| Browser | authorization request | |
+----------+ +----------------+

Figure 1: Device Authorization Flow

Figure 1 所示的 device authorization flow 包含以下步骤:

(A) client 向 authorization server 请求 access, 并在 request 中包含自己的 client identifier.

(B) authorization server 发布 device code 和 end-user code, 并提供 end-user verification URI.

(C) client 指示 end user 在另一台 device 上使用 user agent 访问所提供的 end-user verification URI. client 向 user 提供 end-user code, 供其输入以审查 authorization request.

(D) authorization server 通过 user agent 对 end user 进行 authentication, 并提示 user 输入 device client 提供的 user code. authorization server 验证 user 提供的 user code, 并提示 user 接受或拒绝该 request.

(E) 当 end user 审查 client 的 request 时, 即步骤 D, client 会重复 poll authorization server, 以确定 user 是否完成 user authorization step. client 包含 device code 和自己的 client identifier.

(F) authorization server 验证 client 提供的 device code. 如果授予 client access, 则返回 access token; 如果拒绝 access, 则返回 error; 或者指示 client 应继续 poll.