Just had a similar problem during development. I needed to use a service account to authenticate firebase admin to generate a email sign in link with
const link = await auth.generateSignInWithEmailLink(email, actionCodeSettings);
I go the error here that Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the identitytoolkit.googleapis.com
My solution is now:
- Impersonate the service account, by getting an
Impersonated
Client:
const auth = new GoogleAuth();
const client = await auth.getClient();
const targetClient = new Impersonated({
sourceClient: client,
targetPrincipal: 'myaccount@myproject.iam.gserviceaccount.com',
lifetime: 3600,
delegates: [],
targetScopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
- Extract the Oauth2 credentials
const credentials = await targetClient.getAccessToken();
- Feed the credentials to
initializeApp()
initializeApp({
credential: {
getAccessToken: async () => {
return {
access_token: credentials.res.data.accessToken,
expires_in: Date.parse(credentials.res.data.expireTime) / 1000,
};
},
},
});
Some notes:
What I didn't want to do is create a service account key, download it and use that to authenticate (this would have been the easiest way).
The contents of getAccessToken()
response is not documented and I've pieced it together from looking at the content and tried out the token I've found in there.