0

I'm currently using firebase for authentication. Can I get the login token expiry date? I want to refresh the token when the token had been expired.

Here I retrieve the login token.:

func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
    Auth.auth().addStateDidChangeListener { auth, user in
        if user != nil {

            if let providerData = authUI.auth?.currentUser?.providerData {
                for userInfo in providerData {
                    let currentUser = Auth.auth().currentUser
                    currentUser?.getIDToken(completion: { (idToken, error) in
                        print("idToken====\(String(describing: idToken!))")
                        if let error = error {
                            // Handle error
                            return; 
                        }else{
                        }

                        // Send token to your backend 

                    })

}
KENdi
  • 7,576
  • 2
  • 16
  • 31
user831098
  • 1,803
  • 6
  • 27
  • 47
  • Possible duplicate of [In what period does the firebase's app token changes and how to manage it?](https://stackoverflow.com/questions/37678248/in-what-period-does-the-firebases-app-token-changes-and-how-to-manage-it) – Pipiks Jul 31 '17 at 11:04

1 Answers1

0

You would need to parse the ID token via a JWT parser. You can use something like this library: https://github.com/auth0/JWTDecode.swift

You would then check the exp field. It would contain the UTC timestamp of the expiration time.

bojeil
  • 29,642
  • 4
  • 69
  • 76