Lit
Lit

Reputation: 67

How to initialize Firebase Admin SDK with Google OAuth Token?

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.

Upvotes: 0

Views: 1181

Answers (1)

Hiranya Jayathilaka
Hiranya Jayathilaka

Reputation: 7438

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.

Upvotes: 1

Related Questions