我正在尝试通过 Node.js 后端将 Instagram OAuth 连接到 Firebase。我已成功检索到 Instagram 帐户数据,包括 access_token
,我想将其与我的 Node.js 后端上的 firebase-admin
的 createCustomToken
进行交换。我的目标是生成自定义 token ,以便我的 Angular 应用程序可以在我的 Firebase 应用程序中执行 signInWithCustomToken(token)
操作。从 Instagram 检索数据没有问题,因为我可以在控制台上打印我的 JSON 对象。
当我想将我的 access_token
交换为 Firebase 自定义 token 时出现问题。
我关注了this guide来自 Node.js 的 Firebase 管理页面,我在下面看到一条错误消息
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);
}
我的 Node 应用程序似乎无法初始化与 firebase-admin
的连接,但我不知道解决方案,因为我是这些技术的初学者。请指教。
最佳答案
可以通过将 firebase-tools、firebase-functions 和 firebase-admin 软件包更新到最新版本来解决此问题。
npm install -g firebase-tools@latest
npm install firebase-functions@latest
npm install firebase-admin@latest
引用这个GitHub page了解更多详情。
关于node.js - Firebase 管理员在 initializeApp() 时出现 INVALID_APP_OPTIONS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46504659/