Firebase电子邮件验证不适用于ActionCodeSetting [英] Firebase Email verification not working with ActionCodeSetting

查看:111
本文介绍了Firebase电子邮件验证不适用于ActionCodeSetting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对用户的电子邮件进行验证(在电子邮件模板中使用默认的验证URL),以及一个ActionCodeSetting URL(动态链接)以将用户带回应用程序.我对使用ActionCodeSetting进行Firebase的电子邮件验证应该如何工作感到困惑.我已经阅读了文档的每个可用页面,但仍不清楚如何正确配置继续URL"以不抢占和覆盖默认验证URL.

I'm trying to implement verification of a user's email (with the default verification URL in the email template), AND an ActionCodeSetting URL (dynamic link) to bring the user back to the app. I'm baffled by how Firebase's email verification with ActionCodeSetting is supposed to work. I have read every available page of documentation and it is still unclear to me how to properly configure the "continue URL" to NOT preempt and override the default verification URL.

我做了什么:

  1. 我使用自动生成的电子邮件验证链接测试了电子邮件验证.有效.
  2. 然后,我添加了一个ActionCodeSetting URL,该URL使用的域已添加到XCode项目的关联域"中.这可以使用户在单击验证链接后将其带回应用程序.
  3. 问题:电子邮件验证不再起作用.

这是我实现的代码:

var actionCodeSettings = ActionCodeSettings.init()
                actionCodeSettings.handleCodeInApp = true
                let user = Auth.auth().currentUser
                let urlString = "https://blaproject.page.link/zCB4"
                actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
                actionCodeSettings.setAndroidPackageName("com.example.android", installIfNotAvailable:true, minimumVersion:"12")

                Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings, completion: { (error) in
                    print("verification email sent")
                    print("action code setting URL is: \(String(describing: actionCodeSettings.url))")
                })

这是Firebase控制台中电子邮件模板的默认验证URL:

Here is the default verification URL from the email template in the Firebase console:

> https://blaproject-ea9d6.firebaseapp.com/__/auth/action?mode = & oobCode =

https://blaproject-ea9d6.firebaseapp.com/__/auth/action?mode=&oobCode=

这是上面的代码发送的验证URL:

And here is the verification URL that gets sent by the above code:

HTTPS ://blaproject.page.link链接= HTTPS://blaproject-ea9d6.firebaseapp.com/的/AUTH/动作apiKey%3DAIzaSyAi1fxd-HdkfXzYJxTpwmB3_mVCy5gvWxA%26mode%3DverifyEmail%26oobCode%3DqjvGoqc1n3ya0OIi_tWIYTpp59DYKgB6Sbj0EymN2IkAAAFkYNutMA%26continueUrl%3Dhttps:/? /blaproject.page.link/zCE4%26lang%3Den&apn=com.example.android&amv=12&am磷; IBI = blaproject.blaprojectV0-2&安培; IFL = HTTPS:?//blaproject-ea9d6.firebaseapp.com//AUTH/动作apiKey%3DAIzaSyAi1fxd-HdkfXzYJxTpwmB3_mVCy5gvWxA%26mode%3DverifyEmail%26oobCode%3DqjvGoqc1n3ya0OIi_tWIYTpp59DYKgB6Sbj0EymN2IkAAAFkYNutMA%26continueUrl%3Dhttps ://blaproject.page.link/zCE4%26lang%3Den

https://blaproject.page.link?link=https://blaproject-ea9d6.firebaseapp.com//auth/action?apiKey%3DAIzaSyAi1fxd-HdkfXzYJxTpwmB3_mVCy5gvWxA%26mode%3DverifyEmail%26oobCode%3DqjvGoqc1n3ya0OIi_tWIYTpp59DYKgB6Sbj0EymN2IkAAAFkYNutMA%26continueUrl%3Dhttps://blaproject.page.link/zCE4%26lang%3Den&apn=com.example.android&amv=12&ibi=blaproject.blaprojectV0-2&ifl=https://blaproject-ea9d6.firebaseapp.com//auth/action?apiKey%3DAIzaSyAi1fxd-HdkfXzYJxTpwmB3_mVCy5gvWxA%26mode%3DverifyEmail%26oobCode%3DqjvGoqc1n3ya0OIi_tWIYTpp59DYKgB6Sbj0EymN2IkAAAFkYNutMA%26continueUrl%3Dhttps://blaproject.page.link/zCE4%26lang%3Den

所以我的问题是,为什么此URL不验证用户的电子邮件,然后使用继续URL(及相关域)触发应用程序打开?它只会触发应用打开,而无需验证用户的电子邮件.

So my question is, why does this URL not verify the user's email and then use the continue URL (and the associated domain) to trigger the app to open? It only triggers the app to open, without verifying the user's email.

感谢您提供的任何提示,可以帮助我了解我不了解的内容:)

Thanks for any tips you can provide to help me understand what I'm not understanding :)

推荐答案

当链接触发您的应用打开时.您需要从深层链接解析oobCode.您可以使用FDL客户端库来获取深层链接.请参阅以下有关深层链接格式以及如何解析代码的文档: https://firebase.google.com/docs/auth/custom-email-handler

When the link triggers your app to open. You need to parse the oobCode from the deep link. You can use FDL client library to get the deep link. Refer to the following documentation on the format of the deep link and how to parse the code: https://firebase.google.com/docs/auth/custom-email-handler

获得代码后,需要使用auth.applyActionCode(code) API进行应用.这将验证电子邮件.

Once you get the code, you need to apply it using the auth.applyActionCode(code) API. This will verify the email.

验证后,您可以调用user.reload()来更新用户的emailVerified属性.如果您使用的是Firebase安全规则,还可以强制user.getIdToken(true)强制使用更新的已验证电子邮件来刷新令牌.

After verification, you can call user.reload() to update the emailVerified property on the user. You can also force user.getIdToken(true) to force refresh the token with the updated verified email if you are using Firebase security rule.

这篇关于Firebase电子邮件验证不适用于ActionCodeSetting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆