了解用于身份验证的 Firebase 动态链接中的状态
抱歉,我在理解 Firebase 动态链接时遇到了很多困难。
我的用例是:用户想要从移动应用程序重置密码(或发送电子邮件验证)。
- 该请求是使用 Firebase 身份验证和自定义处理程序发出的(使用自定义域:https://example.com/auth)
ActionCodeSettings
如下所示:
final ActionCodeSettings codeSettings = ActionCodeSettings(
url: 'https://links.example.com/auth?email=$email',
iOSBundleId: Constants.iosBundleID,
androidPackageName: Constants.androidBundleID,
androidInstallApp: true,
dynamicLinkDomain: "links.example.com",
);
- 用户点击通过电子邮件收到的链接并被重定向到网站(由 Firebase Hosting 托管,位于:example.com)
- 当用户完成密码重置后,我希望通过“启动”
continueUrl
来重定向他,这应该将他带回到移动应用程序。continueUrl
:'https://links.example.com/auth?email=$email'
但是这不起作用,所以我猜测我在某个地方做错了什么。
- 在我的 iOS 配置中,我将
关联域
添加为:applinks:links.example.com
。
,我添加了:(
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://links.example.com/auth</string>
</array>
并且还尝试了:
)
- 在
Info.plist
文件中 我的 Android 配置我已将其添加到我的AndroidManifest.xml
中:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="links.example.com" android:scheme="https"/>
</intent-filter>
有趣的是,在 Android 上,完成上述步骤后(在智能手机上的网站上),如果我启动 ContinueUrl
它提示用户是否重定向回应用程序或留在浏览器上打开 URL。
当然,我在 Firebase 动态链接控制台中创建了一个子域:links.example.com
作为 URL 前缀。
这是我的问题:
continueUrl
是否应该重定向回应用程序?- 上面描述的
ActionCodeSettings
中的continueUrl
是否正确?我在文档中看到始终使用example.com
作为continueUrl
,但它会与用于托管的自定义域发生冲突,对吧?因此,我将links.example.com
作为continueUrl
,自定义 Firebase 身份验证处理程序是example.com/auth
以确实重定向到我的网站中的正确网页。 - 这种情况下的托管
firebase.json
配置是什么? - 最后的链接如下所示:
https://example.com/auth?mode=resetPassword&oobCode=T0qn8aj_p7TJBWyE5eUh7_7ZwIqwtJ7Q-i8LDf4QrIsAAAF_u6Bi6Q&apiKey=AIzaSyAzPqhZFKAyfQDeN4DGGjI9VCTEBe_mLc4&continueUrl=https%3A%2F%2Flinks.example.com%3Flink%3Dhttps%3A%2F%2Flinks.example.com%2Fauth%3Femail%253Dtestmail12%40gmail.com%26apn%3Dcom.example.android%26amv%26ibi%3Dcom.example.ios%26ifl%3Dhttps%3A%2F%2Flinks.example.com%2Fauth%3Femail%253Dtestmail12%40gmail.com&lang=fr
- 您发现有什么问题或缺失吗?操作完成后会阻止移动应用程序重定向的东西吗?
- 我应该如何处理
continueUrl
参数才能重定向到应用程序?它是在某个事件后自动完成的,还是应该开发人员编写代码来“推送”包含此链接的新网页,并且它会自动看到这不是要在网页中处理的链接,从而重定向到移动应用程序?
预先非常感谢您对其工作原理的任何解释!
I am sorry i have much trouble understanding Firebase Dynamic links.
My use case is : a user wants to reset his password from the mobile app (or send an email verification).
- The request is made using Firebase Authentication with a custom handler (with custom domain : https://example.com/auth)
- The
ActionCodeSettings
looks like :
final ActionCodeSettings codeSettings = ActionCodeSettings(
url: 'https://links.example.com/auth?email=$email',
iOSBundleId: Constants.iosBundleID,
androidPackageName: Constants.androidBundleID,
androidInstallApp: true,
dynamicLinkDomain: "links.example.com",
);
- The user clicks on the link he received by email and gets redirected to the website (hosted by Firebase Hosting under : example.com)
- When the user has finished resetting his password, i would expect to redirect him by "launching" the
continueUrl
that should take him back to the mobile app.continueUrl
: 'https://links.example.com/auth?email=$email'
However this doesn't work so i am guessing that i am doing something wrong somewhere.
- In my iOS config, i have added the
Associated Domains
as :applinks:links.example.com
.
In theInfo.plist
file i have added :
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://links.example.com/auth</string>
</array>
(and have also tried with : <string>https://links.example.com</string>
)
- In my Android config I have added this to my
AndroidManifest.xml
:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="links.example.com" android:scheme="https"/>
</intent-filter>
Fun fact, on Android after the above steps are completed (on website from the smartphone), if i launch the continueUrl
it prompts the user whether to redirect back to the app or stay on the browser to open the URL.
I have of course created a sub-domain : links.example.com
in the Firebase Dynamic links console as an URL prefix.
Here are my questions :
- Is the
continueUrl
supposed to redirect back to the app ? - In the
ActionCodeSettings
continueUrl
described above is correct? I see in the documentation always usingexample.com
as thecontinueUrl
, but it would be in conflict with the custom domain used for hosting right ? So i have putlinks.example.com
as thecontinueUrl
and the custom Firebase auth handler isexample.com/auth
to indeed redirect to the correct web page in my website. - What is the Hosting
firebase.json
configuration for such case ? - The final link looks like this :
https://example.com/auth?mode=resetPassword&oobCode=T0qn8aj_p7TJBWyE5eUh7_7ZwIqwtJ7Q-i8LDf4QrIsAAAF_u6Bi6Q&apiKey=AIzaSyAzPqhZFKAyfQDeN4DGGjI9VCTEBe_mLc4&continueUrl=https%3A%2F%2Flinks.example.com%3Flink%3Dhttps%3A%2F%2Flinks.example.com%2Fauth%3Femail%253Dtestmail12%40gmail.com%26apn%3Dcom.example.android%26amv%26ibi%3Dcom.example.ios%26ifl%3Dhttps%3A%2F%2Flinks.example.com%2Fauth%3Femail%253Dtestmail12%40gmail.com&lang=fr
- Do you see anything wrong or missing ? Something that would prevent the mobile app redirection after the operation completes ?
- What should I do with the
continueUrl
param to gets redirected to the app ? Is it automatically done after some event or should the developer writes code to "push" a new web page containing this link and it will see automatically that's not a link to handle in a web page, thus redirect to the mobile app ?
Thanks a lot in advance for any explanations on how this works !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于明白了这是如何工作的:
ContinueUrl
必须是用于在移动应用程序中处理的那个,所以如果您使用:这意味着您必须创建一个
动态链接
前缀 URL :Firebase 控制台中的https://links.example.com/auth
。您还必须将其添加到您的 iOS
Info.plist
文件中,如问题中所述。此外,当您使用自定义域时,您需要确保如文档中所述,URL 前缀和域不同,例如 :
而不是 :
这意味着通过使用
https://links.example.com /auth
作为 URL 前缀,您需要使用另一个域来处理链接。就我而言,我以这种方式构建了 url:
并添加了
https://redirect.example.com/auth
作为 URL 前缀。这可以防止托管级别的
example.com
与链接域名和 URL 前缀相同的links.example.com
之间发生冲突。另外,不要忘记在 Firebase 控制台的 Firebase 身份验证登录方法中将新的动态链接域添加为
白名单
域,否则您将收到domain-denied
错误。希望这能帮助其他人更好地理解它是如何工作的。
I have finally understood how this works :
The
continueUrl
must be the one used to handle back in the mobile app so if you use :This means you have to create a
dynamic link
prefix URL :https://links.example.com/auth
in the firebase console.You must also add it to your iOS
Info.plist
file as stated in the question.Also, when you use a custom domain you need to make sure as stated in the documentation that the URL prefix and the domain are different such as :
And not :
This means that by using
https://links.example.com/auth
as URL prefix, you need to use another domain to deal with the link.In my case, i have built the url this way :
And added
https://redirect.example.com/auth
as URL prefix.This prevent both conflicts between
example.com
at the hosting level andlinks.example.com
from having both link domain name AND Url prefix identical.Also, don't forget to add new dynamic links domain as
whitelisted
domains in the Firebase Authentication Sign-In methods in Firebase console or you will get adomain-denied
error.Hope this will help others to understand better how this works.