![](/img/trans.png)
[英]Domain-wide delegation using default credentials in Google Cloud Run
[英]Firebase - NodeJS: Domain-Wide Delegation with OAuth2 for Google API
此Firebase Cloud Function應該使用具有域范圍委派的 Cloud API ,以便在Firebase數據庫更改時,任何用戶都可以更新一些 G Suite管理面板用戶信息。
我應該使用哪種程序包方法來為我的應用程序獲取整個domian范圍的委托。
firebase.auth.GoogleAuthProvider()
google.auth.OAuth2
new GoogleAuth()
我並未將有關Google身份識別平台的點點滴滴連絡起來, 在這一步 ,我被困在這里。 Firebase托管的Node.js應用程序如何針對Google API請求將網絡和訪問令牌組合在一起?
Firebase項目使用Google Cloud Platform項目,因此
我有...
service account actor
添加到項目中 我應該使用...
Firebase :可能要查看Google OAuth2設置的白名單區域 ,和/或使用從firebase獲得的services.json 。
通過googleapis的 Google API :即使我使用firebase.auth.GoogleAuthProvider()
來驗證用戶,也可以使用google.auth.OAuth2
從GCP(例如應用程序或計算引擎)獲取域范圍的委托
通過google-auth-library進行的 Google Auth :同樣,即使我使用firebase.auth.GoogleAuthProvider()
驗證用戶,也可以使用new GoogleAuth()
從GCP(例如應用程序或計算引擎)獲取域范圍的委托
我學過:
googleapis
不適用於客戶端(瀏覽器)。 我現在正在嘗試在Firebase Cloud Functions中使用它 使用googleapis
通過JWT服務令牌進行服務帳戶身份驗證。
以下代碼已部署到Firebase Cloud Functions,並且日志似乎表明身份驗證已成功。
Firebase功能日志
NodeJS代碼
// Firebase Admin SDK
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
// Google APIs
const googleapis = require('googleapis')
const drive = googleapis.drive('v3')
const gsuiteAdmin = googleapis.admin('directory_v1')
// Service Account Key - JSON
let privatekey = require("./privatekey.json")
let jwtClient = new googleapis.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
['https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/admin.directory.user'])
// Firebase Cloud Functions - REST
exports.authorize = functions.https.onRequest((request, response) => {
//authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err)
return
} else {
console.log("Successfully connected!")
}
response.send("Successfully connected!")
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.