Email-link-auth not working: Firebase Auth always returns false for isSignIn(withEmailLink:)

1,213 views
Skip to first unread message

Tim Carr

unread,
Mar 24, 2018, 12:11:28 AM3/24/18
to Firebase Google Group
I'm attempting to follow the instructions here: https://firebase.google.com/docs/auth/ios/email-link-auth
... and here (for the dynamic links part): https://firebase.google.com/docs/dynamic-links/ios/receive
... to have my iOS app tell Firebase to send an email with a link, which when the user opens on their device, causes my app to have an authenticated User object. 

    @objc func handleFirebaseDynamicLink(_ link: DynamicLink) {
        guard let link
= link.url?.absoluteString else {
           
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, link had no url")
           
return
       
}
        guard let email
= self.emailAddressLastEntered, Auth.auth().isSignIn(withEmailLink: link) else {
           
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, not a signInWithEmailLink or no emailAddress?")
           
return
       
}
 

 
ISSUE: For some reason, Auth.auth().isSignIn(withEmailLink:) is returning false, even though the link it is given appears to be correct: 

`(lldb) po link
"https://<redacted>.firebaseapp.com/__/auth/action?apiKey=<redacted>&mode=signIn&oobCode=123459g71QBFRozWp4fvi-izDstx9BE2o3zhPc_jZQAAAFiU_tqpg&continueUrl=https://<redacted>/applinks/firebaseprovider/signin"`

I verified that the URLs are whitelisted under firebase console -> Authentication -> Sign In Method -> Authorized Domains

If I ignore this and just call `Auth.auth().signIn(withEmail: email, link: link)`, it crashes with an exception of trying to insert a nil value into an NSDictionary :(

Here is the code i'm calling to generate the email send, which is successful. I get the email and copy the link to the simulator:

            let actionCodeSettings = ActionCodeSettings.init()
            actionCodeSettings
.url = URL.init(string: "https://<redacted>/applinks/firebaseprovider/signin")
            actionCodeSettings
.handleCodeInApp = true
            actionCodeSettings
.setIOSBundleID(Bundle.main.bundleIdentifier!)
           
Auth.auth().sendSignInLink(toEmail: emailAddress, actionCodeSettings: actionCodeSettings, completion: { (error) in
               
if let error = error {
                   
WLog("FirebaseProvider signIn: ERROR on sendSignInLink: \(error.localizedDescription)")
                    waitingForUserBlock
(false)
                   
return
               
}
               
self.emailAddressLastEntered = emailAddress
               
self.signedInBlock = signedInBlock
                waitingForUserBlock
(true)
           
})



... and here's the AppDelegate code that gets to the handler:

        - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
           
DDLogInfo(@"AppDelegate continueUserActivity: %@", userActivity.debugDescription);
            BOOL handled
= [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) {
               
if (error) {
                   
DDLogWarn(@"AppDelegate continueUserActivity: ERROR on handleUniversalLink: %@", error.debugDescription);
                   
return;
               
}
               
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
           
}];
           
return handled;
       
}


       
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
               
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
               
if (dynamicLink) {
                   
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
                   
return YES;
               
} else {
                   
DDLogWarn(@"%s, WARNING: openURL returning FALSE because i didn't know the prefix: %@", __PRETTY_FUNCTION__, url.absoluteString);
               
}
           
return false;
       
}



I also made sure to re-download the `GoogleService-Info.plist` file, and I see in there that `IS_SIGNIN_ENABLED` is `YES` as i'd expect.

All help much appreciated.

Bassam

unread,
Mar 24, 2018, 6:02:32 PM3/24/18
to Firebase Google Group
Hey Tim, seems strange it would return false.
Passing a link like: https://<redacted>.firebaseapp.com/__/auth/action?apiKey=<redacted>&mode=signIn&oobCode=123459g71QBFRozWp4fvi-izDstx9BE2o3zhPc_jZQAAAFiU_tqpg&continueUrl=https://<redacted>/applinks/firebaseprovider/signin

Should return true based on the implementation:

 Are you sure this is the link you are passing to isSignInWithEmailLink?

Best regards,
Bassam

Tim Carr

unread,
Mar 26, 2018, 10:30:20 AM3/26/18
to Firebase Google Group
Hello Bassam,

Thank you very much for your reply.
Yes, i'm sure that what I pasted is exactly what i'm passing in - that was copied from the debugger because I thought the same as you, I must be passing in the wrong link. But it seems correct.
Could there be something misconfigured about my app? I'm calling [FIRApp configure] only in didFinishLaunching... does it need to be called in openURL or continueUserActivity too? or is there something in my Google-services plist file that might be wrong?

thanks
-tim

Tim Carr

unread,
Mar 26, 2018, 10:30:24 AM3/26/18
to Firebase Google Group
Update, thanks to your link to the source-code, I found the bug in the Firebase code. Please take a look at:

Any chance you're on a team that would be able to get this into a minor update, like a 4.11.1? 
Thanks again for your help.

On Saturday, March 24, 2018 at 6:02:32 PM UTC-4, Bassam wrote:

Bassam

unread,
Mar 26, 2018, 1:31:32 PM3/26/18
to Firebase Google Group
Hey Tim, I will relay this issue to the relevant folks. I think we may need to make some additional fixes there. We will make sure the fix is in the next release.

Best regards,
Bassam
Reply all
Reply to author
Forward
0 new messages