2017-09-30 34 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 
 
});

相关问题