Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid authentication token after 1 hour - Disk Persistence in Firebase

I'm using Firebase UI Auth to handle email signin in my app and I enabled Disk Persistence so that the data can be accessed offline. But after signed in for an hour in the app, I get this warning in the logcat.

W/PersistentConnection: pc_0 - Auth token revoked: expired_token (Auth token is expired.)
W/PersistentConnection: pc_0 - Authentication failed: invalid_token (Invalid claim 'kid' in auth header.)
W/PersistentConnection: pc_0 - Authentication failed: invalid_token (Invalid claim 'kid' in auth header.)
... repeatedly
... and sometimes
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

When I received this message, the app can't do any firebase save/retrieve new uncached data operation unless I sign out/clear data and then sign in again. Then the problem happened again after about an hour after signed in. I have followed this token refresh troubleshooting guide (added my debug and production key SHA1 to both Firebase and Google API Console) and it does not fix this. I have used the latest google-services.json from the Firebase Console in my project.

I'm also already using latest Firebase SDK and Play Services library

compile 'com.google.android.gms:play-services-auth:9.2.1'
compile 'com.google.firebase:firebase-core:9.2.1'
compile 'com.google.firebase:firebase-database:9.2.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.firebaseui:firebase-ui-auth:0.4.3'

I enabled the persistence in the Application class.

public class Application extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    }
}

Any ideas? Feel free to comment if you need more clarification or if I do not provide enough information. Thank you

like image 753
Wilik Avatar asked Jul 23 '16 17:07

Wilik


People also ask

How long do Firebase auth tokens last?

Create custom tokens using the Firebase Admin SDK At a minimum, you need to provide a uid , which can be any string but should uniquely identify the user or device you are authenticating. These tokens expire after one hour.

How do I authenticate a Firebase realtime database?

You can use Firebase Authentication to have users to sign in to your app. Firebase Authentication includes drop-in support for common authentication methods like Google and Facebook, as well as email and password login, anonymous login, and more. User identity is an important security concept.

What is Firebase persistence?

Value. Description. firebase.auth.Auth.Persistence.LOCAL. 'local' Indicates that the state will be persisted even when the browser window is closed or the activity is destroyed in React Native.


1 Answers

The kid 22fb7e6f95c657f4407e04e97c984bb6dbbcfeb3 is not recognized by the Firebase server. getToken() should definitely return different tokens if the account emails are different. Please file a ticket to Firebase, including the whole token payload from both your apps.

like image 122
Jin Liu Avatar answered Oct 14 '22 01:10

Jin Liu