【问题标题】:Why does Google OAuth API requires client_secret for the device flow? Is it safe to store the secret in an app that can be downloaded?为什么 Google OAuth API 需要设备流的 client_secret?将秘密存储在可下载的应用程序中是否安全?
【发布时间】:2022-01-11 06:58:53
【问题描述】:

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=...'

我收到以下错误:

{
  "error": "invalid_request",
  "error_description": "Missing required parameter: client_secret"
}

如果我通过client_secret,它可以工作。

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

  1. 为什么 Google API 需要 client_secret 用于设备流? OAuth 2.0 for TV and Limited-Input Device Applications 没有提供任何解释。
  2. 假设我的客户属于“电视和有限输入的客户 ID”类型,公开 client_secret 是否安全?我认为通常不鼓励这样做,所以我想将此问题仅限于 Google API。我的应用程序可以下载,而且秘密基本上是硬编码的,因此暴露给大家。如果秘密被泄露,我想知道会有什么影响。

【问题讨论】:

    标签: oauth-2.0 google-oauth openid-connect google-openid


    【解决方案1】:

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

    https://oauth2.googleapis.com/token
    

    虽然设备代码端点是

    https://oauth2.googleapis.com/device/code
    

    在您使用标准 oauth2 端点时咨询此page,您可能属于本节内容

    而不是希望您使用设备端点的本节。

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

    curl -d "client_id=client_id&scope=email%20profile" \
         https://oauth2.googleapis.com/device/code
    

    【讨论】:

    猜你喜欢
    • 2016-07-16
    • 1970-01-01
    • 2020-06-28
    • 2021-02-02
    • 2023-01-17
    • 2018-05-29
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多