question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

firebase get token authentication failed first run

See original GitHub issue

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Android Studio Arctic Fox | 2020.3.1 Patch 2 Build #AI-203.7717.56.2031.7678000, built on August 27, 2021

    implementation platform(‘com.google.firebase:firebase-bom:28.4.2’) implementation ‘com.google.firebase:firebase-messaging’ implementation ‘com.google.firebase:firebase-analytics’

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I can only replicate this in every fresh install app by wiping the data and then run app. works fine when uninstalling then run app and subsequent runs.

throws Topic sync or token retrieval failed on hard failure exceptions: AUTHENTICATION_FAILED. Won’t retry the operation.

Relevant Code:

public class StobyFirebaseMessagingService extends FirebaseMessagingService
{ ... }

// MainActivity - getting the token
FirebaseMessaging.getInstance().getToken()
                .addOnCompleteListener(new OnCompleteListener<String>() {
                    @Override
                    public void onComplete(@NonNull Task<String> task) {
                    ....
                    }
});

// for workaround - I invoke the above token snippet twice in different Fragment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gsakakiharacommented, Oct 25, 2021

It should happen soon after the device has network connectivity. The emulator is an unusual case because it just starts immediately on first start/after a data wipe. Real devices go through the setup process, which usually allows enough time for the device to register before the user has a chance to do anything else or install apps, so it’s rare for an app to encounter this. Note that it’s possible that a device fails to register for some reason, so your app should always be able to handle the AUTHENTICATION_FAILED case gracefully, but in general you shouldn’t expect this to be a common case.

0reactions
asciicodecommented, Oct 25, 2021

When you mention wiping data, is this on an emulator? AUTHENTICATION_FAILED generally indicates a problem with the device’s authentication and could happen if you are trying to get a token before the device has finished setting up/registering. Could you try waiting a few minutes after wiping the emulator before trying to get the token and seeing if you still get AUTHENTICATION_FAILED?

Seems working as you said(need around 2-3mins), In what lifecycle the device will finish setting up/registering/uploading info? I want to hook up after registering and get token.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Token Authentication error - Stack Overflow
I think you didn't sign before uploading files. In onCreate() of launcher activity, try this code FirebaseAuth mAuth = FirebaseAuth.
Read more >
Manage User Sessions | Firebase Authentication - Google
Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token...
Read more >
getToken succeeds or fails randomly · Issue #5081 - GitHub
getToken seems to randomly fail without plausible explanation. I run it with the exact same config on the same device multiple times in...
Read more >
invalid_token (Invalid claim 'aud' in auth token.) - Google Groups
This error basically means the SDK failed to authenticate to the Firebase Database because the auth token was for a different project. There...
Read more >
Firebase auth: Error getting access token from GOOGLE_OIDC
For me, Web client secret was wrong. Above, next to "Web SDK configuration", mouse over info icon, click the link for "Google API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found