【问题标题】:Can Google Calendar API support 'service account authorization without OAuth` method?Google Calendar API 可以支持“没有 OAuth 的服务帐户授权”方法吗?
【发布时间】:2021-05-06 10:59:50
【问题描述】:

我正在尝试使用不使用 OAuth 方法访问日历 API 的服务帐户实现授权。 https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth

With some Google APIs, you can make authorized API calls using a signed JWT directly as a bearer token, rather than an OAuth 2.0 access token.

If the API you want to call has a service definition published in the Google APIs GitHub repository, you can make authorized API calls using a JWT instead of an access token. To do so:

Using any standard JWT library, such as one found at jwt.io, create a JWT with a header and payload like the following example:
    {
      "alg": "RS256",
      "typ": "JWT",
      "kid": "abcdef1234567890"
    }
    .
    {
      "iss": "123456-compute@developer.gserviceaccount.com",
      "sub": "123456-compute@developer.gserviceaccount.com",
      "aud": "https://firestore.googleapis.com/",
      "iat": 1511900000,
      "exp": 1511903600
    }

上述文档中提到 JWT aud 字段应为 https://SERVICE.googleapis.com/ 格式。由于Calendar端点不是格式,是否可以通过这种授权机制来访问Calendar API?

日历端点是https://www.googleapis.com/

【问题讨论】:

  • 哈什么? “没有 OAuth 方法”我们可以得到一个 minimal reproducible example 你想在这里做什么?授权在您正在访问的 API 之外。在尝试授权您的服务帐户时,您不应该关心日历端点。
  • @DaImTo 请检查developers.google.com/identity/protocols/oauth2/…。 JWT aud 字段中需要日历端点。
  • 您为什么要手动执行此操作?你为什么不使用其中一个库?只是为了让您知道我已经为此工作了十年,但我还没有设法从头开始获得服务帐户授权。
  • @DaImTo 我需要使用 HTTP 进行构建。我可以在 Sheet API 中执行此操作,因为它具有 API 端点 https://sheets.googleapis.com/。但是 Calendar API 不支持它,因为端点。
  • 您仍在混合服务帐户和 api 端点。我很想看看您如何使用纯 HTTP 为 Google 表格创建服务帐户授权。

标签: google-api google-calendar-api


【解决方案1】:

是的。 Google 提供日历服务 API 端点为https://calendar-json.googleapis.com/。 https://support.google.com/workspacemigrate/answer/9222865?hl=en

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多