0
votes

I'm using node.js and passport-google-oauth20 package for use login system on my web console.

With passport, I got a Google account's oauth token(access token and refresh token) and want to initialize firebase admin sdk with it.

var refreshToken; // Get refresh token from OAuth2 flow

admin.initializeApp({
  credential: admin.credential.refreshToken(refreshToken),
  databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});

This is the code that I can find at Google Firebase website(https://firebase.google.com/docs/admin/setup). So I need a refreshToken for initialize the Firebase Admin SDK.

But the code makes error Failed to parse refresh token file: Error: ENOENT: no such file or directory, open 'REFRESHTOKEN'

I tried to set parameter with JSON object that contains refreshtoken, client_id, client_secret, project_id, type. But it still doesn't work.

How can I initialized firebase admin sdk with google oauth token?

Add : I'm not planning to use Service Account for server-side authentication because of security issue.

1

1 Answers

1
votes

The argument passed into admin.credential.refreshToken() method must be an object with the properties client_id, client_secret, refresh_token and type. Or it must be a path to a file containing such an object.