Firebase authentication tokens expiration duration

2020-06-23 06:54发布

问题:

I just upgraded to the new version of Firebase and I can't find where I can set the expiration duration of my Firebase authentication tokens. It used to be under the authentication section in Firebase's old layout (I had it set for 1 year). Does Firebase still have this?

回答1:

If you keep using the Firebase 2.x SDK, your expiration period will be the same as before. You cannot change the value anymore though.

If you upgrade your code to use the 3.x SDK, it'll switch to user a never-expiring ID token and a quickly expiring access token. See this answer for more on that: Firebase authentication duration is too persistent



回答2:

I am able to login to firebase using below code:

this.firebaseAuth
        .auth.signInWithCustomToken(this.token)
        .then(value => {
           var that=this;
           firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
//get authorization token idToken here
}

I am able to to query firebase after login, but after refresh firebase not able to recognise the user?

I have stored token in localstorage but how to set token in angular firebase request? for below code:

this.afs.doc(
        `user/${user.uid}`
    ).set(Object.assign({}, auser), { merge: true });