'Google sign I didSignInFor. I am getting ID Token expired

I using google with sign in. From today morning, google sign in was not working. Not sure why its happening. I am getting error :

ID Token expired

On my console error. Any one please help me why its happening. I am new to it.

@IBOutlet weak var googleSignInBtn: UIButton! 

 @IBAction func GoogleLogin(_ sender: Any) {
        
        GIDSignIn.sharedInstance().signIn()
    }

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
 if (error == nil) {
} else {
 print("\(error.localizedDescription)")
}
}

My system time and date is correct only. Even the token is correct only. Android is working fine. But in iOS its getting this issues. Should i need to do pod install again ?

Thanks



Solution 1:[1]

Add GoogleService-Info.plist file to your project root folder

write your clientId in didfinishLaunch:

GIDSignIn.sharedInstance()?.clientID = "***********.apps.googleusercontent.com"

Go to project -> Info -> URL Types and add URL Scheme from googleService-Info.plist in this format:

com.googleusercontent.apps.***************

Add following code in button action:

GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().delegate=self
GIDSignIn.sharedInstance().signIn()

Add extension to your ViewController:

extension ViewController: GIDSignInDelegate
{
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
    if error == nil
    {
        let image: URL = user.profile.imageURL(withDimension: 70)!
        let imageString:String = image.absoluteString
        
        socialData(social_id: user.userID ?? "", email: 

user.profile.email ?? "", name: user.profile.name ?? "", image: imageString, type: 2)
        }
        else
        {
            print(error)
            self.SocialDataDelegate?.returnSocial()
        }
    }
}

Solution 2:[2]

I had the same return with Error "ID Token expired"

I made a lot of research and tests, so here is result:

  • At first, I found out that the error was only on one device. Other devices with this gmail didn't give that error
  • Secondly, I checked what is the difference between them
  • On this "bug"-device gmail was using long time ago or was singed out, but credentials was saved anyway.

Solution: You or your users have to sign in into gmail again. You can do it in Gmail app.

It helped for me and I hope it will help for you too.

Solution 3:[3]

Change your device's date and time to set automatically. You device must have correct date and time otherwise Google will throw "ID Token expired" error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 DmitriyK
Solution 3 Abdul Rehman