6
votes

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

2
It's kind of a long shot, but can you check the date / time on your device to make sure it's set correctly? There can occasionally be token-related issues if your device is set to an incorrect time. - Michael Lehenbauer
It's set "automatic" so it should be correct (based on internet time). I don't know if this has something to do with the firebase-ui library. Thank you for your comment, any other solution that I could try? :) - Wilik
After the user signs in, can you grab a latest Firebase Auth token by calling FirebaseUser.GetToken(true), and print out the 'kid' in the token header? Firebase Auth token is a Json Web Token (JWT) and you can use jwt.io to see the fields inside a JWT. - Jin Liu
hi @JinLiu, the 'kid' from the token header is 22fb7e6f95c657f4407e04e97c984bb6dbbcfeb3 - Wilik
I think I have to say this, I have two apps using the same firebase project. After calling getToken() in both apps, I found out that their token is the same even though both of them are signed in using different accounts. I have tried FirebaseUser.getEmail() and the output for both apps is different. - Wilik

2 Answers

1
votes

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.

1
votes

In Firebase 3, the maximum life-time of a JWT is 60 minutes. So after 1 hour, you will have to regenerate the access token. As for the invalid claim "kid", you do not need to pass any kid payload to your JWT.

NOTE: The problem you are facing is because of the recent changes made to the JWT structure and work flow. I faced the same problems - I revised my code as per the new JWT specs and things started working.