You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

iOS端Google登录报错ID Token expired,求技术支持

Troubleshooting iOS Google Sign-In "ID Token expired" Issue

Hey there! Let's break down this issue step by step since you mentioned you're a beginner—no worries, we'll get this sorted out.

First, let's address your question about pod install: while re-running it can sometimes fix dependency inconsistencies, let's start with more targeted troubleshooting first (since Android works fine, your backend/Google Cloud config is likely correct).

Possible Causes & Fixes

1. Local Cache Glitch

iOS's Google Sign-In SDK might be caching expired token data, even if you think your token is valid. Try these quick fixes:

  • Uninstall the app from your iOS device, restart the device, then reinstall and test the login again.
  • Clear the app's stored data (you can do this via Settings > [Your App] > Clear Cache if your app supports it).

2. Verify Token Details in Callback

Add some logging to your sign-in callback to check the actual token your app is receiving. This will help confirm if the token is truly expired:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if (error == nil) {
        if let auth = user.authentication {
            print("ID Token: \(auth.idToken ?? "No token found")")
            print("Token Expiration Date: \(auth.accessTokenExpirationDate ?? Date())")
        }
    } else {
        print("\(error.localizedDescription)")
    }
}

Check if the printed expiration date is in the past. If it is, the SDK is fetching an expired token—this points to either a configuration issue or SDK version problem.

3. SDK Version Compatibility

Older versions of the GoogleSignIn SDK might have bugs related to token handling on newer iOS versions. Check your Podfile:

  • If you're using an unversioned dependency (pod 'GoogleSignIn'), try specifying a stable recent version like:
    pod 'GoogleSignIn', '~> 7.0'
    
  • Run pod update GoogleSignIn to get the latest compatible version, then test again.

4. Reinstall Pods (Last Resort)

If the above steps don't work, a clean pod install might resolve hidden dependency conflicts:

  • Delete the Pods folder from your project directory
  • Delete the Podfile.lock file
  • Run pod install in your terminal, then rebuild and test the app.

Final Notes

Don't forget to double-check that your iOS app's bundle ID matches exactly what's configured in your Google Cloud Console (under the OAuth 2.0 client ID for iOS). Even a tiny mismatch can cause unexpected token issues.

内容的提问来源于stack exchange,提问作者Samarat

火山引擎 最新活动