kan*_*oid 13 android google-authentication facebook-authentication firebase-authentication
我遇到Android Firebase Auth使用com.google.gms:google-services:3.0.0和的问题com.google.firebase:firebase-auth:9.0.1.
使用Firebase(Google或Facebook)验证后1小时,我收到以下错误消息:
W/PersistentConnection: pc_0 - Authentication failed: expired_token (Auth token is expired)
为什么Firebase令牌在1小时后过期以及如何延长此有效期?
UPDATE
我仍然遇到此问题,Firebase令牌在1小时后过期.现在我收到以下消息:
W/PersistentConnection: pc_0 - Authentication failed: invalid_token (Invalid claim 'kid' in auth header.)
我感谢任何帮助.
尝试实现FirebaseInstanceIdService获取刷新令牌。
访问注册令牌:
您可以通过扩展FirebaseInstanceIdService来访问令牌的值。确保您已将该服务添加到清单中,然后getToken在 的上下文中调用onTokenRefresh,并记录值,如下所示:
    @Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
    // TODO: Implement this method to send any registration to your app's servers.
    sendRegistrationToServer(refreshedToken);
}
每当生成新令牌时都会触发 onTokenRefreshcallback,因此在其上下文中调用可确保
getToken您正在访问当前可用的注册令牌。FirebaseInstanceID.getToken()如果尚未生成令牌,则返回 null。
代码:
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";
    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);
        // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(refreshedToken);
    }
    // [END refresh_token]
    /**
     * Persist token to third-party servers.
     *
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {
        // Add custom implementation, as needed.
    }
}
我希望它对你有帮助。
| 归档时间: | 
 | 
| 查看次数: | 11487 次 | 
| 最近记录: |