簡體   English   中英

如何讓一個服務帳戶模擬另一個服務帳戶? (節點.js)

[英]How can I have a service account impersonate another service account? (Node.js)

我通過將GOOGLE_APPLICATION_CREDENTIALS環境變量設置為我的 App Engine 服務帳戶的密鑰路徑(例如example@appspot.gserviceaccount.com )來進行身份驗證。

如果日歷直接共享到 App Engine 服務帳戶,我可以這樣做:

let googleCalendar = google.calendar({
  version: 'v3',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/calendar'],
  })
});

但我希望用戶與我擁有的不同服務帳戶google-calendar@example.iam.gserviceaccount.com共享他們的日歷。 所以我希望 App Engine 服務帳戶模擬google-calendar帳戶。 我已經嘗試過這個(以及其他一些小的變化):

let googleCalendar = google.calendar({
  version: 'v3',
  auth: new google.auth.GoogleAuth({
    clientOptions: {
      subject: 'google-calendar@uniserval-app.iam.gserviceaccount.com'
    },
    scopes: ['https://www.googleapis.com/auth/calendar'],
  })
});

我收到 401 錯誤: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.

我嘗試讓我的 App Engine 服務帳戶成為google-calendar服務帳戶上的成員,並授予它各種角色,例如Service Account UserService Account Token Creator - 但沒有任何變化。

我懷疑代碼是正確的,我只是沒有配置正確的角色......但此時我一直在搜索如何做到這一點 2 天,我找不到任何關於如何做到這一點的文檔.

您的語法看起來正確,只是您似乎誤解了將哪個電子郵件地址設置為主題。 主題是您希望代表其操作的用戶帳戶。

new google.auth.GoogleAuth({
  clientOptions: {
    subject: 'someone@yourdomain.com'
  },
  scopes: ['https://www.googleapis.com/auth/calendar'],
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM