accessToken refresh with Firebase

I'm developing an Angular application, and i connecting to the GCP console from Angular (without the gcp main js). Its working well, but sadly the request must inserted the accessToken and the accessToken maximum time in GCP services maximum 3600sec, and after that I get 4XX errors, that my http request not working, and don't get any result.

If logout, and login again (with Popup), the 3600sec resets, and start "counting" the 3600 sec again. I using AngularFireAuth and I tried many solutions to reset the accessToken, after 3500 sec, but not working.

I found an old solution, that the Google has an getAccessToken function with force refresh option, but today this function is deprecated.

You can see my solutions, which called after every 3500 sec, but not working, the accessToken not refreshed, and got GCP error.

private ReAuthenticate(res: any) {
    this.afAuth.signInWithCredential(res.credential)
      .then((user) => {
        // This not refresh the accessToken 
        /*const credential = user.credential as OAuthCredential;
        if (user && user.credential && credential && credential.accessToken) {
          this.secureLS.secureSetItem('idToken', credential.accessToken);
        }*/
         
        this.afAuth.currentUser.then(result => {
          if (result && user.credential) {
            result.reauthenticateWithCredential(user.credential).then(userCredential => {
              if (userCredential && userCredential.credential) {
                const cred = (userCredential.credential as OAuthCredential);
                if (cred && cred.accessToken) {
                  this.secureLS.secureSetItem('idToken', cred.accessToken)
                }
              }
            })
          }
        });
      })
  }

I don't want to implement the GCP main js in the project, my point to do this with the firebase api, or get a new access refreshed token via http request.



Read more here: https://stackoverflow.com/questions/68464321/accesstoken-refresh-with-firebase

Content Attribution

This content was originally published by NetMajom at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: