3.1. 设备授权请求 (Device Authorization Request)
本规范定义一个新的 OAuth endpoint: device authorization endpoint. 它独立于 [RFC6749] 中定义的 OAuth authorization endpoint, 后者由 user 通过 user agent, 即 browser, 进行交互. 相比之下, 使用 device authorization endpoint 时, device 上的 OAuth client 会直接与 authorization server 交互, 不会在 user agent 中呈现 request, 而 end user 会在另一台 device 上授权该 request. 该交互定义如下.
client 通过向 device authorization endpoint 发出 HTTP POST request, 从 authorization server 请求一组 verification code, 从而启动 authorization flow.
client 按 [RFC6749] Appendix B 使用 application/x-www-form-urlencoded format, 并在 HTTP request entity-body 中使用 UTF-8 character encoding 包含以下 parameter, 向 device authorization endpoint 发出 device authorization request:
client_id
- 如果 client 未按 [RFC6749] Section 3.2.1 所述向 authorization server 进行 authentication, 则 REQUIRED.
- client identifier, 如 [RFC6749] Section 2.2 所述.
scope
- OPTIONAL. access request 的 scope, 如 [RFC6749] Section 3.3 所定义.
例如, client 发出以下 HTTPS request:
POST /device_authorization HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
client_id=1406020730&scope=example_scope
来自 device 的所有 request MUST 使用 Transport Layer Security (TLS) protocol [RFC8446], 并实现 BCP 195 [RFC7525] 的 best practice.
发送时不带 value 的 parameter MUST 被视为已从 request 中省略. authorization server MUST 忽略无法识别的 request parameter. request 和 response parameter MUST NOT 被包含超过一次.
[RFC6749] Section 3.2.1 的 client authentication requirement 适用于此 endpoint 上的 request. 这意味着 confidential client, 即已经建立 client credential 的 client, 按与向 token endpoint 发出 request 时相同的方式进行 authentication, public client 则提供 client_id parameter 来标识自身.
由于该 protocol 具有 polling 性质, 如 Section 3.4 所指定, 需要注意避免 token endpoint 的容量过载. 为避免对 token endpoint 发出不必要 request, client SHOULD 只在 user 提示时才开始 device authorization request, 而不是自动开始, 例如 app 启动时或先前 authorization session 过期或失败时.