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
})
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.