2017-09-30 33 views
0

我試圖通過Node.js後端將Instagram OAuth連接到Firebase。我已成功檢索了Instagram帳戶數據,包括我想在我的Node.js後端與firebase-admincreateCustomToken交換的access_token。我的目標是生成自定義令牌,以便我的Angular應用程序可以在我的Firebase應用中執行signInWithCustomToken(token)。從Instagram上檢索數據沒有問題,因爲我可以在控制檯上打印我的JSON對象。Firebase Admin INVALID_APP_OPTIONS error initializeApp()

當我想將我的access_token更換爲Firebase自定義令牌時發生問題。

我遵循了火力地堡管理頁面this guide對Node.js的,我面臨着以下

throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, "Invalid Firebase app options passed as the first argument to initializeApp() for the " +

Error: Invalid Firebase app options passed as the first argument to initializeApp() for the app named "[DEFAULT]". The "credential" property must be an object which implements the Credential interface.

錯誤消息這是我對相關問題的代碼。

// authService.js 
 

 
var fbAdmin = require('firebase-admin'); 
 
var serviceAccount = require('./key/key.json'); 
 

 
function createFirebaseToken(instagramID) { 
 

 
     // I copy & pasted this var from other class 
 
     var config = { 
 
      apiKey: "MY_FIREBASE_APIKEY", 
 
      authDomain: "MY_APP.firebaseapp.com", 
 
      databaseURL: "https://MY_APP.firebaseio.com", 
 
      storageBucket: "MY_APP.appspot.com", 
 
     }; 
 

 
     console.log(fbAdmin.credential.cert(serviceAccount)); // serviceAccount successfully printed on console 
 

 
     // Error appears when executing this function 
 
     fbAdmin.initializeApp({ 
 
      serviceAccount: fbAdmin.credential.cert(serviceAccount), 
 
      databaseURL: config.databaseURL 
 
     }); 
 

 
     const uid = `instagram:${instagramID}`; 
 
     
 
     // Create the custom token. 
 
     console.log(uid); 
 
     return fbAdmin.auth().createCustomToken(uid); 
 
    }

看來,我節點應用程序無法初始化firebase-admin連接,但我不知道該解決方案,因爲我對這些技術的初學者。請指教。

回答

1

剛剛在Firebase Admin Release Notes上於2017年5月的版本5.0.0上發現serviceAccount已被刪除。因此,我不用強制使用serviceAccount,而是使用credential

fbAdmin.initializeApp({ 
 
    credential: fbAdmin.credential.cert({ 
 
     projectId: '<APP_ID>', 
 
     clientEmail: "[email protected]<APP_ID>.iam.gserviceaccount.com", 
 
     privateKey: "-----BEGIN PRIVATE KEY-----\n<MY_PRIVATE_KEY>\n-----END PRIVATE KEY-----\n" 
 
    }), 
 
    databaseURL: config.databaseURL 
 
});

相關問題