Я ссылался на следующий URL.
https://firebase.google.com/docs/web/setup
https://firebase.google.com/docs/auth/web/google-signin
Код index.js выглядит следующим образом.
var App = require('actions-on-google').DialogflowApp;
var functions = require('firebase-functions');
var firebase = require('firebase');
var admin = require('firebase-admin');
/**
* Responds to any HTTP request that can provide a "message" field in the body.
*
* @param {!Object} req Cloud Function request context.
* @param {!Object} res Cloud Function response context.
*/
exports.testMethod = (req, res) => {
// Initialize Firebase
admin.initializeApp({
credential:admin.credential.cert({
apiKey:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain:"test.firebaseapp.com",
databaseURL:"https://xxxxx.firebaseio.com",
projectId:"test",
storageBucket:"test.appspot.com",
messagingSenderId:"xxxxxxxxxxx"
})
});
var app = new App({request:req, response:res});
let user = app.getUser();
console.log('User is ' + user);
let id_token = app.getUser().accessToken;
console.log('accessToken is ' + accessToken);
//var id_token = googleUser.getAuthResponse().id_token
// Build Firebase credential with the Google ID token.
var credential = firebase.auth.GoogleAuthProvider.credential(id_token);
// Sign in with credential from the Google user.
firebase.auth().signInWithCredential(credential).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
};
Произошла следующая ошибка.
Error: Certificate object must contain a string "private_key" property. at FirebaseAppError.Error (native) at FirebaseAppError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28) at new FirebaseAppError (/user_code/node_modules/firebase-admin/lib/utils/error.js:70:23) at new Certificate (/user_code/node_modules/firebase-admin/lib/auth/credential.js:108:19) at new CertCredential (/user_code/node_modules/firebase-admin/lib/auth/credential.js:174:33) at Object.cert (/user_code/node_modules/firebase-admin/lib/firebase-namespace.js:175:58) at exports.testMethod (/user_code/index.js:15:34) at /var/tmp/worker/worker.js:684:7 at /var/tmp/worker/worker.js:668:9 at _combinedTickCallback (internal/process/next_tick.js:73:7)