[英]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 User
和Service 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.