If you’re using firebase-tools as a module, you can get the refresh token of a user by
import { getGlobalDefaultAccount } from "firebase-tools/lib/auth.js";
const account = getGlobalDefaultAccount();
console.log(account.tokens.refresh_token);
I’m looking for a way to use the logged in user’s(firebase-tools) refresh token as the credential for the Firebase Admin SDK. Something like:
import { initializeApp, refreshToken } from "firebase-admin/app";
const admin = initializeApp({
credential: refreshToken(account.tokens.refresh_token),
});
I’ve tried running the code snippet above, but it looks like the refreshToken
method interprets the account.tokens.refresh_token
as a path to a file(maybe because it’s a string). So I tried changing it to an object like so:
import { initializeApp, refreshToken } from "firebase-admin/app";
const admin = initializeApp({
credential: refreshToken({
refresh_token: account.tokens.refresh_token,
}),
});
However, it’s now raising an error stating that it’s missing the client_secret
and client_id
properties, which the account
object does not have. AFAIK, only service accounts have those.