Firebase Cloud Functions: app/invalid-credential failed to fetch a valid Google OAuth2 access token Firebase Admin SDK
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 7.5.0
Platform: macOS
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
I am new to Cloud Functions. I followed the docs, and the new initialization syntax for firebase-admin, but I am getting an auth error when running the function on the server and on a localhost.
https://firebase.google.com/docs/functions/beta-v1-diff#new_initialization_syntax_for_firebase-admin
@firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"."}
I tried instantiating the sdk with a serviceAccountKey
, same issue. https://firebase.google.com/docs/admin/setup#initialize_the_sdk
The function is being triggered on localhost and on the server, and error is being thrown once the call to the database is being made at gettingUser()
When running locally after building:
$ firebase experimental:functions:shell
firebase > const data = {some_article...}
firebase > addingNewArticle(data)
'Successfully invoked function.'
firebase > > New article created articleId1
DEBUG: @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"."}
/index.ts
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
export const addingNewArticle = functions.database
.ref('/articles/{articleId}')
.onCreate(async (snapshot, context) => {
const articleId = context.params.articleId
const result = await gettingUser();
console.log(`From onCreate ${result}`);
console.log(`New article created ${articleId}`)
const articleVal = snapshot.val()
const name = articleVal.name
const addedById = articleVal.addedById
console.log(`${name} was added by: ${addedById}`);
console.log(`burgersVal: ${articleVal}`);
console.log(`snapshot: ${snapshot}`);
return Promise.all([])
})
export async function gettingUser() {
const result = await admin.database().ref(`users/fnkjasdfadsfna.d`).once('value');
console.log(`Looging new user ${result.val()}`);
return result.val()
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:39 (11 by maintainers)
Top Results From Across the Web
Error fetching access token Firebase Cloud Functions
via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error ......
Read more >Learn about using and managing API keys for Firebase - Google
How do I fix this error? "Failed to fetch this Firebase app's measurement ID from the server." The API key used by your...
Read more >腾讯云开发者社区-腾讯云
javascriptfirebasefirebase-cloud-messaginggoogle-cloud-functionsfirebase-admin ... "credential" property failed to fetch a valid Google OAuth2 access token ...
Read more >getting a Google OAuth2 access token error ENOTFOUND
The Cloud Functions for Firebase SDK const functions ... "credential" property failed to fetch a valid Google OAuth2 access token with the ...
Read more >jaybedeau/Firebase-Beginner - Gitter
... "credential" property failed to fetch a valid Google OAuth2 access token with ... I am using angular 5 How can we get...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To anyone experiencing this issue:
GOOGLE_APPLICATION_CREDENTIALS
to a service account or runninggcloud auth application-default login
on your machine.After upgrading to Mac OS Catalina I encountered this issue. What resolved it for me was running the following commands:
firebase login
export GOOGLE_APPLICATION_CREDENTIALS="<PATH_TO_YOUR_SERVICE_ACCOUNT_KEY_JSON>"