跳到主要内容

3.5. 设备访问令牌响应 (Device Access Token Response)

如果 user 已批准 grant, token endpoint 会以 [RFC6749] Section 5.1 中定义的 success response 响应; 否则, 它会以 [RFC6749] Section 5.2 中定义的 error 响应.

除 [RFC6749] Section 5.2 中定义的 error code 外, 以下 error code 专门指定用于 token endpoint response 中的 device authorization grant:

authorization_pending

  • authorization request 仍处于 pending 状态, 因为 end user 尚未完成 user-interaction step (Section 3.3). client SHOULD 重复向 token endpoint 发出 access token request, 此过程称为 polling. 每次新 request 之前, client MUST 至少等待 device authorization response 的 interval parameter 指定的秒数 (见 Section 3.2), 如果未提供则等待 5 秒, 并遵守 slow_down error 要求的任何 polling interval 增加.

slow_down

  • authorization_pending 的变体. authorization request 仍处于 pending 状态且 polling 应继续, 但此 request 和所有后续 request 的 interval MUST 增加 5 秒.

access_denied

  • authorization request 被拒绝.

expired_token

  • device_code 已过期, 且 device authorization session 已结束. client MAY 开始新的 device authorization request, 但 SHOULD 等待 user interaction 后再重新开始, 以避免不必要的 polling.

authorization_pendingslow_down error code 定义了特别独特的行为, 因为它们表示 OAuth client 应通过重复 token request 继续 poll token endpoint, 并实现上面定义的精确行为. 如果 client 收到带有任何其他 error code 的 error response, 它 MUST 停止 polling, 并且 SHOULD 相应处理, 例如向 user 显示 error.

遇到 connection timeout 时, client MUST 在重试前单方面降低 polling frequency. RECOMMENDED 使用 exponential backoff algorithm 实现这一点, 例如每次发生此类 connection timeout 时将 polling interval 加倍.

本规范的假设是, user 用于授权 request 的独立 device 没有方式与运行 OAuth client 的 device 通信. 该 protocol 只需要单向 channel, 以最大化 protocol 在受限环境中的可行性, 例如运行在 TV 上且只能发出 outbound request 的 application. 如果所选 user-interaction interface 存在 return channel, 则 device MAY 等到该 channel 通知 user 已完成操作后再发起 token request, 作为 polling 的替代方式. 但是, 此类行为超出本规范范围.