Google as an Auth provider doesn't work on iOS saved to homescreen
Problem
[REQUIRED] Describe your environment Operating System version: iOS 10 Firebase SDK version: 4.1.3 Firebase Product: auth [REQUIRED] Describe the problem Steps to reproduce: 0. Save the app on the homescreen on iOS 1. make a redirect or popup login with google Auth provider 2. if redirect: - webview is not a "valid user agent" 3. if popup: - gets stuck in Safari about:blank, doesn't open the app again to pass on the token Relevant Code: [code block]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement Custom URL Scheme for Google Auth on iOS Homescreen App
The issue arises because when the app is saved to the iOS homescreen, it runs in standalone mode, which does not support the standard webview user agent required for Google authentication. This leads to failures in both redirect and popup methods, as the webview is not recognized as a valid user agent, and popups do not return to the app correctly.
Awaiting Verification
Be the first to verify this fix
- 1
Define Custom URL Scheme
Add a custom URL scheme to your iOS app to handle redirects from Google Auth. This allows the app to open back into the correct context after authentication.
xmlAdd the following to your Info.plist: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>yourapp</string> </array> </dict> </array> - 2
Modify Firebase Auth Configuration
Update your Firebase authentication configuration to include the custom URL scheme. This ensures that the authentication process can redirect back to your app correctly.
javascriptfirebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL) .then(() => { // Your authentication logic here }); - 3
Handle URL in App Delegate
Implement the URL handling method in your AppDelegate to capture the redirect from Google Auth and complete the login process.
swiftfunc application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return Auth.auth().canHandle(url) } - 4
Test Authentication Flow
After implementing the above changes, test the authentication flow by saving the app to the homescreen and performing a Google login. Ensure that the app opens correctly after authentication.
- 5
Monitor for Errors
Log any errors encountered during the authentication process to identify if further adjustments are needed. Use Firebase Crashlytics or similar tools for monitoring.
swiftCrashlytics.crashlytics().log("Google Auth Error: \(error.localizedDescription)")
Validation
To confirm the fix worked, save the app to the homescreen, initiate Google authentication, and verify that the app successfully redirects back after login without errors. Check logs for any issues.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep