Firebase 电子邮件无密码身份验证不起作用

问题描述 投票:0回答:1

我对这个过于复杂的获取深层链接的过程束手无策,只是为了尝试使用无密码登录来验证我的用户。

我已经浪费了 3 天的时间来谷歌搜索和观看(实际上很少)处理此功能的 YouTube 视频,并阅读论坛和 github 问题,试图让电子邮件无密码功能发挥作用。该文档充其量是模糊的,并且似乎已经过时,因为它们在不断更新和重构。

在这些指南之间...

https://firebase.google.com/docs/dynamic-links/flutter/create

https://firebase.google.com/docs/auth/flutter/email-link-auth

https://www.youtube.com/watch?v=JHTSgFl8VH0

加上一堆过时的教程只是为了看看我是否能找到任何相似之处,但没有任何效果,

我尝试使用自己的域进行设置,并完成了将 DNS 记录添加到我的虚拟主机站点的步骤,我已将 JSON 文件添加到我域上的 .wellknown 文件夹中。

我已将我的域和 firebase 给我的默认给定域添加到authorizedDomainLists中。

我已经按照许多说明更新了我的 androidManifest:

    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <!-- If a user clicks on a shared link that uses "http" scheme, 
            the app should be able to delegate that traffic to "https". -->
        <data android:scheme="http" />
        <data android:scheme="https" />

        <!-- Include one or more domains that should be verified. -->
        <data android:host="example.page.link" />
    </intent-filter>

我已经添加了动态链接所需的sdks

他们的 pub.dev firebase_dynamicLinks 上的 firebase 示例似乎也不起作用,因为他们在 Main() 方法中调用导航器,但没有这样的上下文...

  final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();

  if (initialLink != null) {
    final Uri deepLink = initialLink.link;
    // Example of using the dynamic link to push user toa different screen
    //Navigator.pushNamed(context, deepLink.path);
  }

  FirebaseDynamicLinks.instance.onLink.listen(
    (pendingDynamicLinkData) {
      // Set up the `onLink` event listener next as it may be received here

      final Uri deepLink = pendingDynamicLinkData.link;
      // Example of using the dynamic link to push the user to a different screen
      //Navigator.pushNamed(context, deepLink.path);
    },
  );

我这里有一个 sendEmailLink 方法:

  Future<AppResponse> sendEmailLink({required String email}) async {
    final actionCodeSettings = ActionCodeSettings(
      url: deepLinkPrefix,
      handleCodeInApp: true,
      androidPackageName: packageName,
      iOSBundleId: packageName,
    );
    await auth.sendSignInLinkToEmail(
      email: email,
      actionCodeSettings: actionCodeSettings,
    );
    return AppResponse.success(
      id: 'sendSignInLinkToEmail',
      message: 'Email link sent successfully',
    );
  }

AppResponse 只是 YouTube 视频中的那个人使用的一个警报对话框。

还有我永远无法使用的retrievelink方法,所以我什至可以看看该部分是否有效。

  // fromColdState means if the app was closed
  Future<AppResponse> retrieveDynamicLinkAndSignIn({required bool fromColdState}) async {
    try {
      PendingDynamicLinkData? dynamicLinkData;

      // Decide where to get link from if App is closed or not
      if (fromColdState) {
        dynamicLinkData = await FirebaseDynamicLinks.instance.getInitialLink();
      } else {
        dynamicLinkData = await FirebaseDynamicLinks.instance.onLink.first;
      }
      if (dynamicLinkData == null) {
        return AppResponse.notFound(
          id: 'retrieveDynamicLinkAndSignIn',
          message: 'No Credentials Found',
        );
      }

      // Check if link is valid
      bool validLink = auth.isSignInWithEmailLink(dynamicLinkData.link.toString());
      if (validLink) {
        // Get the users email address from the continueUrl
        final continueUrl = dynamicLinkData.link.queryParameters['continueUrl'] ?? '';
        final email = Uri.parse(continueUrl).queryParameters['email'] ?? '';

        // Use email to sign in with credentials
        final UserCredential userCredential = await auth.signInWithEmailLink(
          email: email,
          emailLink: dynamicLinkData.link.toString(),
        );

        // Check to make sure user credential is not null
        if (userCredential.user != null) {
          return AppResponse.success(
            id: 'signInWithEmailLink',
            message: 'Signed in successfully',
          );
        } else {
          return AppResponse.notFound(
            id: 'signInWithEmailLink',
            message: 'Not able to sign in',
          );
        }
      } else {
        return AppResponse.notFound(
          id: 'signInWithEmailLink',
          message: 'Link is not valid',
        );
      }
    } catch (e, s) {
      return AppResponse.error(
        id: 'signInWithEmailLink',
        error: e,
        stackTrace: s,
      );
    }
  }

因此,在我的登录屏幕上,我收到了用户的电子邮件,当他们单击“下一步”时,我确实收到了一封电子邮件。我点击电子邮件链接,然后我被发送到浏览器到 Playstore(我显然没有发布我的应用程序),因此它会出现错误,首先,如果安装了该应用程序,它应该打开该应用程序。

我切换回 firebase 给我的默认生成的深度链接,现在我得到了无效的 url,当电子邮件链接将我路由到浏览器时,动态链接被阻止。

我很生气,因为我只是尝试这种方法,因为我试图工作的 OTP 系统被破坏了,因为他们删除了 SafetyNet,并迫使每个人都使用 PlayIntegrity 进行 AppCheck,我也花了几天时间研究试图得到工作。

因此,任何帮助或提示将不胜感激。或者,如果有人有一本更新的或最新的指南,并且确实有效,那将是一个救星。

flutter firebase firebase-authentication firebase-dynamic-links password-less
1个回答
0
投票

我没有答案,但我找不到如何评论你的问题。我还在努力获得无密码电子邮件身份验证以与 Firebase 和 Flutter 配合使用。我可以收到注册电子邮件,但它有一个无效链接,如下所示: https://mycustomdomain.com/?link=https://my-firebase-app.firebaseapp.com/__auth/action?apiKey%3DMY_VALID_API_KEY%26mode#3DsignIn%26oobCode%3DSEEMINGLY_VALID_CODE%26ContinueUrl%3Dthe.url.I。 put.in.ActionCodeSettings%26lang%3Den&apn=my.android.package&amv=12

与我在网上找到的其他示例相比,有两件事对我来说很突出:

  1. 此链接以我的自定义域而不是 my-firebase-app 开头。
  2. URL编码不一致,有些&=被%26和%3D取代,但最后却出现了&apn=...&amv=12。

如果我在收到电子邮件后立即手动编辑此 URL https://my-firebase-app.firebaseapp.com/__/auth/action?apiKey=MY_VALID_API_KEY&mode=signIn&oobCode=CODE_FROM_EMAIL&continueUrl=the.url.I.put。 in.ActionCodeSettings&lang=en&apn=my.android.package&amv=12 并粘贴到我的计算机和 Android 模拟器上的浏览器中,我被重定向到 continueUrl,但没有关于成功验证我的电子邮件或成功登录的消息。我在 Firebase 控制台的“身份验证”下也看不到任何用户帐户。

© www.soinside.com 2019 - 2024. All rights reserved.