Firebase service account does not work anymore on localhost

2,708 views
Skip to first unread message

Mustafa Ekim

unread,
Mar 22, 2021, 11:21:34 AM3/22/21
to Firebase Google Group
Hi,

We have been actively using firebase since 2019. Today, without any apparent reason, the way we use to authentication for firebase on localhost started to throw error:
  • "Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential."
Below is the code we have been using since 2019.

var remoteConfig = {
  credential: admin.credential.cert(serviceAccount as admin.ServiceAccount),
  databaseURL: "XXX",
  storageBucket: "XXX"
}

admin.initializeApp(remoteConfig);

This error may have started to be thrown after I've updated windows but first I am not sure if these are related and second I have no idea about how to fix this.

I've spent a few hours on this but I could not find so much. Anybody has a guess on this bizarre situation?

I am 99% sure that the problem is not related to codes but any suggestion would be appreciated.

Thanks

onabanjo ademola

unread,
Mar 22, 2021, 11:36:51 AM3/22/21
to fireba...@googlegroups.com
Check if you've authorized your domain at firebase authentication Tab.

If you didn't add your domain to this section, all requests made to firebase auth will be rejected.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a2053215-bd7d-44c9-9e29-c22e0e52cbc6n%40googlegroups.com.

Mustafa Ekim

unread,
Mar 22, 2021, 11:53:20 AM3/22/21
to fireba...@googlegroups.com
Hi,

Thanks for the suggestion. Both localhost and our domain are listed as Authorized domain.


--

Mustafa Ekim

--



Sam Stern

unread,
Mar 22, 2021, 12:05:35 PM3/22/21
to Firebase Google Group
Hi Mustafa,

It sounds like the service account you're using locally is no longer valid. Since you mentioned that you recently updated your machine, maybe the key file got moved around or corrupted somehow?  Or maybe someone invalidated it remotely from the console.

The simplest thing to do would be to follow the instructions to download a new one and try using that;
https://firebase.google.com/docs/admin/setup#initialize-sdk

- Sam

--

Mustafa Ekim

unread,
Mar 22, 2021, 12:12:26 PM3/22/21
to fireba...@googlegroups.com
Hello Sam,

Thanks. Actually I created another key under the same service account however that did not help. 

Maybe I should also add that
  • I am using a service account created under google cloud iam - not firebase console.
  • I have another windows machine which continues working fine using the same service account json.

--

Mustafa Ekim

--



onabanjo ademola

unread,
Mar 22, 2021, 12:49:20 PM3/22/21
to fireba...@googlegroups.com
what type of auth method are you using?

Mustafa Ekim

unread,
Mar 22, 2021, 12:54:49 PM3/22/21
to fireba...@googlegroups.com
Hi, we are using the firebase-admin library. I don't know what it uses behind the scenes.

import * as admin from "firebase-admin";
var serviceAccount = {
  "type": "service_account",
  "project_id": "xxx",
  "private_key_id": "xxxx",
  "private_key": "xxx",
  "client_email": "xxx",
  "client_id": "xxx",
  "auth_uri": "xxx",
  "token_uri": "xxx",
  "auth_provider_x509_cert_url": "xxx",
  "client_x509_cert_url": "xxx"
}
var remoteConfig = {
credential: admin.credential.cert(serviceAccount as admin.ServiceAccount),
  databaseURL: "xxx",
  storageBucket: "xxx"
}
admin.initializeApp(remoteConfig);
--

Mustafa Ekim

--



Mustafa Ekim

unread,
Mar 22, 2021, 2:11:13 PM3/22/21
to fireba...@googlegroups.com
  Wow. I've finally found the issue. If you set up your computer's time manually (I had adjusted the time to 2 hours later for some tests) firebase login does not work!
  
--

Mustafa Ekim

--


Sam Stern

unread,
Mar 22, 2021, 2:20:06 PM3/22/21
to Firebase Google Group
Thanks for sharing the solution Mustafa! I don't think I ever would have guessed that.

- Sam

Reply all
Reply to author
Forward
0 new messages