为什么 Google OAuth API 需要 client_secret 用于设备流?将秘密存储在可下载的应用程序中是否安全?

mvl*_*bat 7 google-openid oauth-2.0 google-oauth openid-connect

RFC 8628 没有声明client_secret设备访问令牌请求需要该参数:https://datatracker.ietf.org/doc/html/rfc8628#section-3.4

当我使用 Google API 发出这样的请求时

$ curl --request POST \
  --url 'https://oauth2.googleapis.com/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'grant_type=urn:ietf:params:oauth:grant-type:device_code' \
  --data 'device_code=...' \
  --data 'client_id=...'
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

{
  "error": "invalid_request",
  "error_description": "Missing required parameter: client_secret"
}
Run Code Online (Sandbox Code Playgroud)

如果我通过了client_secret,那就有效了。

如果有人能回答我的两个问题,我将不胜感激:

  1. 为什么Google API需要client_secret设备流?适用于电视和有限输入设备应用程序的 OAuth 2.0未提供任何解释。
  2. client_secret假设我的客户端属于“电视和有限输入的客户端 ID”类型,暴露 是否安全?我认为通常不鼓励这样做,所以我想将这个问题仅限于 Google API。我的应用程序可以下载,并且秘密基本上是硬编码的,从而暴露给所有人。如果这个秘密被泄露,我想知道会产生什么影响。

DaI*_*mTo 0

您正在将请求发送到标准 oauth2 端点

https://oauth2.googleapis.com/token
Run Code Online (Sandbox Code Playgroud)

虽然设备代码端点是

https://oauth2.googleapis.com/device/code
Run Code Online (Sandbox Code Playgroud)

当您使用标准 oauth2 端点时查阅此页面,您可能属于本节的内容

在此输入图像描述

而本节则期望您使用设备端点。

在此输入图像描述

这是在该页面上找到的供客户端使用的示例 TVs and Limited Input devices

curl -d "client_id=client_id&scope=email%20profile" \
     https://oauth2.googleapis.com/device/code
Run Code Online (Sandbox Code Playgroud)