[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getToken succeeds or fails randomly #5081

Closed
schummar opened this issue Jun 30, 2021 · 36 comments
Closed

getToken succeeds or fails randomly #5081

schummar opened this issue Jun 30, 2021 · 36 comments

Comments

@schummar
Copy link
schummar commented Jun 30, 2021

[REQUIRED] Describe your environment

  • Operating System version: Windows 10
  • Browser version: Chrome 91.0.4472.114
  • Firebase SDK version: 8.6.8
  • Firebase Product: cloud messaging

[REQUIRED] Describe the problem

getToken seems to randomly fail without plausible explanation. I run it with the exact same config on the same device multiple times in a row (call deleteToken in between).

Some requests are successful, some fail, seemingly at random. I cannot make out any significant difference between failing and successful requests. Same config, request headers contain same values for x-goog-api-key and x-goog-firebase-installations-auth
Request payloads have the same shape and same value for applicationPubKey.

The returned error is:

code: 401
message: "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
status: "UNAUTHENTICATED"

Steps to reproduce:

  • Call getToken
  • Sometimes the function is successful, token is returned, messages arrive, all perfect. Sometimes the request fails.

Relevant Code:

await messaging.getToken({
    vapidKey: publicVapidKey,
    serviceWorkerRegistration: await serviceWorkerRegistration,
})

Example reponse overview

To test it I'm running a loop of

  • deleteToken()
  • wait 2 minutes
  • getToken()
  • wait 30 seconds

And the result is:
image

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@dnimon
Copy link
dnimon commented Jun 30, 2021

I am also seeing this issue, although it occurs every time in our environment. Receiving the following error, and nothing has changed in our application in regards to firebase integration:

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

@renanfferreira
Copy link

We are getting this error too.

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

@renanfferreira
Copy link

@schummar have you found a solution?

@schummar
Copy link
Author
schummar commented Jun 30, 2021

No solution, only a not-so-great workaround.
I just retry until it works in 30s intervals. But that means it can take quite some time until the subscription becomes active.

@renanfferreira
Copy link

In our case it always fails.

@hbdev86
Copy link
hbdev86 commented Jun 30, 2021

Yes, we got this same error too, since last 4-5 hours. it was working correctly before.
image

@akp111
Copy link
akp111 commented Jul 1, 2021

Getting this error message since yesterday. It was working perfectly in both extension and react app.
An error occurred while retrieving token. FirebaseError: Messaging: A problem occurred while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. (messaging/token-subscribe-failed). at http://localhost:3000/static/js/vendors~main.chunk.js:4303:33 at step (http://localhost:3000/static/js/vendors~main.chunk.js:61747:17) at Object.next (http://localhost:3000/static/js/vendors~main.chunk.js:61678:14) at fulfilled (http://localhost:3000/static/js/vendors~main.chunk.js:61633:24)

@seniordev-ca
Copy link

image

It was working correctly yesterday, but it's not working now on my react app.
I tried to delete the app from firebase and create it again but still fails.
@schummar Have you found a solution?

@will-ks
Copy link
will-ks commented Jul 1, 2021

We are also seeing this error a lot, first occurrence was at June 29, 2021 4:44:25 AM UTC. We have also made no changes in this timeframe.

In my testing, the error occurs probably 95% of the time. Eventually a call will succeed.

@Jayaram7797
Copy link
Jayaram7797 commented Jul 1, 2021

We are also facing same issue since yesterday evening (Aroud 5PM IST). There is no problem for existing active subscribers, but this is affecting our new users and old users
1]. Old users, whose token has expired
2]. New users, whose new token is to be registered.
We checked some of our partners implementing server side token registration ... it looks like its working fine for them. firebase team should atleast inform us if there is any update in this regard. Since yesterday no new subscribers for our website.

We have a feeling that they replaced fcm token registration authentication code with login authentication for google signin.

@legraphista
Copy link
legraphista commented Jul 1, 2021

Started implementing push notifications 2 days ago for our app and spent way too much debugging this thinking that it's an issue on our side (give me 8 hours of my life back pls 😅)

Our calls usually fail 80% of the time.
The workaround on our side was to retry messaging.getToken 5 times at 3 seconds intervals. If that fails, we notify the user to try again later.

I've checked the requests going to https://fcmregistrations.googleapis.com/v1/projects/{PROJECT_ID}/registrations and the payload is identical between succeeding and failing requests. The same goes for x-client-data and x-goog-firebase-installations-auth, they are identical.

@deivisondfs2
Copy link

This also happens to me :(
Yesterday it was normal and today I'm getting this error too.
Does anyone have any updates or where can we try to get a status?
I just created a new account for test and entered the new credentials but the error remains.

@lesjames
Copy link
lesjames commented Jul 1, 2021

I'm getting a 401 on the call to registrations as well. Just noticed it yesterday. It's happening in production and no code has changed there.

@kyftball
Copy link
kyftball commented Jul 1, 2021

Same. Getting 401. It appeared to work until I unregistered the service worker during testing. Now it continuously throws the same error. No code or api changes on my side

@gach87
Copy link
gach87 commented Jul 1, 2021

image

No report in the status page neither

@ghanavel
Copy link
ghanavel commented Jul 1, 2021

image

@ghanavel
Copy link
ghanavel commented Jul 1, 2021

I am getting this issue since beginning , never given successful token, I tried with new vapidKey as well

@looptheloop88
Copy link

We are currently looking into this issue internally. We'll keep this thread posted for any updates.

@Jaimerojo
Copy link

I have the same issue since yesterday

Captura de Pantalla 2021-07-01 a la(s) 12 20 50

@schummar
Copy link
Author
schummar commented Jul 1, 2021

It seems by now all of our requests fail all the time. Yesterday it felt like 50/50. So is it possible some update/cert/whatever has been rolled out to the servers gradually in the last days?

@Stiveknx
Copy link
Stiveknx commented Jul 1, 2021

Another thing to add:

After many failures, I've managed to get some registrations.

  • Sending notifications, didn't fail, but also didn't reach the destination.
  • If I try to generate a new token, I first get an FAIL to delete the current registration.
  • Than, I get the same stuck problem, fails 90% of trying to get new tokens.

The fail to delete the current registration:
Screenshot_20210701_184928
Screenshot_20210701_184856

PS.: I've never called delete before.
If I get a new token again, and try to delete, same problem.

@sahejsingh
Copy link

copying from: #2364 (comment)

I ran into this issue this morning. (1st Jul)

POST https://fcmregistrations.googleapis.com/v1/projects/my-project-id/registrations 401 (Unauthorized)
<call-stack>
index.html:630 Unable to get permission. FirebaseError: Messaging: A problem occurred while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. (messaging/token-subscribe-failed).
    at api.ts:67
    at tslib.es6.js:102
    at Object.next (tslib.es6.js:83)
    at r (tslib.es6.js:73)

here is how it happened

  • created client-1, got notifications working.
  • for some reason I happened to delete the client-1 from firebase console.
  • created client-2
  • copied the new firebaseConfig from console.
  • got the error now.
  • Noticed, the Web API Key is the same for both the clients. there are not restrictions on the web api key.
  • I have followed everything I could (unregister service worker)

Firebase JS Version: 8.6.8

scripts imported like so:

<script src="https://www.gstatic.com/firebasejs/8.6.8/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.8/firebase-messaging.js"></script>
var firebaseConfig = {
  // CONFIG COPIED FROM FIREBASE CONSOLE.
};

firebase.initializeApp(firebaseConfig);

const messaging = firebase.messaging();


  messaging
    .getToken({ vapidKey: "MY_PUB_KEY" })
    .then((currentToken) => {
      console.log(currentToken)
    })
    .catch(function (err) {
      // handle error
    });

@dkensiski
Copy link

We have identified and believe we have resolved the issue.

@gach87
Copy link
gach87 commented Jul 2, 2021

Confirmed the resolution in multiple devices

@gach87
Copy link
gach87 commented Jul 2, 2021

image
Now the error is sending messages to the devices, not getting the token

@ghanavel
Copy link
ghanavel commented Jul 2, 2021

We have identified and believe we have resolved the issue.

Today morning I Could see token.

@Jayaram7797
Copy link

Finally ... a sigh of relief ... thank you team firebase .. :)

@schummar
Copy link
Author
schummar commented Jul 2, 2021

I can confirm, that so far it looks good. I could not observe any more failures this morning.

@akp111
Copy link
akp111 commented Jul 2, 2021

@schummar Did you change anything on your end?
I am not getting the error message but I am also not able to generate the token

@schummar
Copy link
Author
schummar commented Jul 2, 2021

No changes, it just works now.

@akp111
Copy link
akp111 commented Jul 2, 2021

Thank you for informing

@marosivanco
Copy link

Any idea in which releases will it land? I am particularly interested in v9.0.0-beta...

@legraphista
Copy link

Any idea in which releases will it land? I am particularly interested in v9.0.0-beta...

By the looks of it, the issue was backend related.
On my end, the errors have subsided without any change to my implementation (version 8.7.0)

@looptheloop88
Copy link

Per checking, the issue is now resolved. This is a backend issue and we didn't change anything in the current JS SDK.

@Jaimerojo
Copy link

finally works

@firebase firebase locked and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests