通过代码使用自定义基础URL创建Firebase电子邮件验证链接

发布于 2025-02-09 17:53:22 字数 1955 浏览 1 评论 0原文

在我们的项目中,我们使用了几个不同的应用程序,它们使用了使用Firebase进行身份验证的相同用户(角色&特权在我们自己的服务器中存储和管理,具体取决于他们已注册的应用程序,Firebase仅用于使用Firebase身份验证用户)。

想象一下,例如,带有驱动程序和乘客应用程序的Uber状设置。

我们希望我们的用户在这些应用程序中注册并接收服务器创建的电子邮件验证链接(使用外部SMPT服务实际发送电子邮件)。

如果用户单击电子邮件验证链接,则应将它们重定向到相应的Android/iOS应用程序。因此,我们需要使用两个不同的基础网址来创建验证链接 这样:

  • pressenger.myapp.com/welcome?mode=verifyemail& ambcode = xxx& continueurl = https%3a %2F%2FPassenger.myapp.com& lang = de
  • driver.myapp.com/welcome?mode=verifyeMail& oobcode=xxxx& continueurl=https%3A%3A%3A%3A%2F%2F%2fdriver.myapp.myapp.com&.amp.amp;lang = de

到目前为止,我们无法仅使用 firebase admin sdk 。我们尝试创建有点像这样的链接:

EmailAddress email = new EmailAddress(Faker.instance().internet().safeEmailAddress())
// create account using email + password
// ...
ActionCodeSettings settings = ActionCodeSettings.builder()
    .setUrl("https://passenger.myapp.com")
    .setHandleCodeInApp(true)
    .build();
String verifyEmailLink = FirebaseAuth.getInstance().generateEmailVerificationLink(email.getValue(), settings);

我们的主要问题是Firebase仅使用localhost:3100/Wincome作为基本URL创建这些链接(不是passenger.myapp.com)。这似乎是在发生这种情况,因为我们添加了localhost:3100/Welcome作为Firebase Console中的默认操作URL:

“在此处输入图像描述”

我们可以在创建创建时以某种方式更改动作URL使用Firebase Admin SDK的链接,取决于注册发生在?

作为解决方法的链接,我们目前在创建这些链接后使用一个简单的字符串重复位置,但是我想知道是否在那里是一种更好的方法,或者如果这可能导致我们尚未意识到的问题:

verifyEmailLink = verifyEmailLink.replace("http://localhost:3100/welcome", "https://passenger.myapp.com/welcome");

In our project, we have several different apps that are using the same set of users that we authenticate using firebase (roles & privileges are stored and managed in our own server depending on the app they have been registerd for, firebase is only used to authenticate users).

Imagine e.g. an Uber-like setup with a driver and a passenger application.

We want our users to register inside these apps and receive an email verification link created by our server (using an external SMPT service for actually sending the email).

If a user clicks on an email verification link, they should be redirected right back into the respective android/iOS app. For that reason, we need to create our verification links with two different base urls like this:

  • passenger.myapp.com/welcome?mode=verifyEmail&oobCode=xxx&continueUrl=https%3A%2F%2Fpassenger.myapp.com&lang=de
  • driver.myapp.com/welcome?mode=verifyEmail&oobCode=xxx&continueUrl=https%3A%2F%2Fdriver.myapp.com&lang=de

So far, we have been unable to create links like these using only the firebase admin sdk. We tried creating the links somewhat like this:

EmailAddress email = new EmailAddress(Faker.instance().internet().safeEmailAddress())
// create account using email + password
// ...
ActionCodeSettings settings = ActionCodeSettings.builder()
    .setUrl("https://passenger.myapp.com")
    .setHandleCodeInApp(true)
    .build();
String verifyEmailLink = FirebaseAuth.getInstance().generateEmailVerificationLink(email.getValue(), settings);

Our main issue is that firebase only uses localhost:3100/welcome as the base url to create those links (not passenger.myapp.com). This seems to be happening because we added localhost:3100/welcome as the default action url in the firebase console:

enter image description here

Can we somehow change the action url when creating the link using the firebase admin sdk depending on what app (passenger vs driver) the registration has happened in?

As a workaround, we currently work with a simple string-replace after creating these links, but I was wondering if there is a better way or if this might lead to problems that we are just not aware of yet:

verifyEmailLink = verifyEmailLink.replace("http://localhost:3100/welcome", "https://passenger.myapp.com/welcome");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文