Android 登录与 Apple 和 firebase flutter

gg1*_*g11 9 android firebase-authentication flutter sign-in-with-apple

我正在使用 sign_in_with_apple 并且我的登录可以用于 ios,但 android 组件不起作用。

我已经浏览了文档和问题,但没有明确的答案。https://github.com/aboutyou/dart_packages/tree/master/packages/sign_in_with_apple

我坚持这个插件的文档部分说:

在您的服务器上使用 Apple 回调登录(在 WebAuthenticationOptions.redirectUri 中指定),使用以下 URL 安全地重定向回您的 Android 应用程序:

intent://callback?${PARAMETERS_FROM_CALLBACK_BODY}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end

PARAMETERS FROM CALLBACK BODY 应填充您在端点上从 Apple 服务器接收到的 urlencoded 正文,并且应更改包参数以匹配您的应用程序的包标识符(如在 Google Play 商店中发布的)。保持回调路径和 signinwithapple 方案不变。

此外,在客户端处理传入凭据时,请确保仅在您自己的服务器验证传入代码参数后才覆盖用户的当前(来宾)会话,这样您的应用程序就不容易受到恶意传入链接(例如日志记录)的影响退出当前用户)。

部分说:来自回调主体的参数应填充您在端点上从 Apple 服务器接收的 urlencoded 主体。我不确定如何获得它并正确格式化重定向 URL 的 PARAMATERS_FROM_CALLBACK_BODY 部分以使其适用于 Android。

Eri*_* Su 9

2024 年更新:

如果您使用firebase_auth版本 4.4.0 及更高版本。您不需要该sign_in_with_apple包即可在任何平台(Android、iOS、Windows 等)上运行 Apple 登录流程。

只需使用该signInWithProvider方法并为其提供一个AppleAuthProvider对象,该对象捆绑在firebase_auth包中。

AppleAuthProvider appleProvider = AppleAuthProvider();
appleProvider = appleProvider.addScope('email');
appleProvider = appleProvider.addScope('name');
// the line below will start the Apple sign in flow for your platform
final credential = await FirebaseAuth.instance.signInWithProvider(appleProvider);
Run Code Online (Sandbox Code Playgroud)

您仍然需要在 Apple Developer 控制台上进行与之前相同的设置。


Cha*_*esC 6

我有完全相同的问题,实际上我昨天在他们的回购中提出了一个问题

我不确定您是否正在尝试为回调设置自己的后端服务器,但是为了回答您的问题,您需要理解的部分仅适用于需要实现自己的回调 API 的人.

我确实通过以下步骤使 Android 的 Apple Sign In 工作(通过网络浏览器身份验证):

注意由于您已经让 iOS 部分正常工作,所以我假设您已经完成了基本配置

  1. 根据他们的文档设置 glitch.com 服务,这部分很容易理解。

  2. 然后你想实现你的 signInWithApple 调用作为以下参考注意:SERVER_AS_PER_THE_DOCS需要根据你的 glich 服务进行更新。

    Future<FirebaseUser> signInWithApple() async {
    var redirectURL = "https://SERVER_AS_PER_THE_DOCS.glitch.me/callbacks/sign_in_with_apple";
    var clientID = "AS_PER_THE_DOCS";
    final appleIdCredential = await SignInWithApple.getAppleIDCredential(
        scopes: [
          AppleIDAuthorizationScopes.email,
          AppleIDAuthorizationScopes.fullName,
        ],
        webAuthenticationOptions: WebAuthenticationOptions(
            clientId: clientID,
            redirectUri: Uri.parse(
                redirectURL)));
    final oAuthProvider = OAuthProvider(providerId: 'apple.com');
    final credential = oAuthProvider.getCredential(
      idToken: appleIdCredential.identityToken,
      accessToken: appleIdCredential.authorizationCode,
    );
    final authResult =
        await SignInUtil.firebaseAuth.signInWithCredential(credential);
    return authResult.user; }
    
    Run Code Online (Sandbox Code Playgroud)

  • 有没有办法在不使用“Glitch”的情况下使重定向网址正常工作? (2认同)
  • 为什么 firebase 不为我们处理这个问题?在应用身份验证之前,它不是要求提供所有必要的凭据(在控制台中)吗?这真的很糟糕:( (2认同)