You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple Sign In首次登录后无法获取DisplayName与Email问题排查求助

Apple Sign In 后续登录无法获取Email与DisplayName问题解决

问题现象

首次使用Apple Sign In登录时流程正常,能获取到用户的Email和DisplayName,但后续登录时无法获取这两个字段。

原因分析

这是Apple Sign In的原生设计逻辑:Apple仅在用户首次授权登录时返回完整的用户身份信息(邮箱、全名),后续用户再次登录时,Apple只会返回用户的唯一标识(userID),不会重复返回邮箱和全名——因为默认应用已保存过这些信息。

解决方案

  • 首次登录成功后,立即将获取到的appleCredential.email和appleCredential.fullName存储到你的后端数据库,或者Firebase的用户Profile中,与用户的Apple userID(appleCredential.userIdentifier)关联绑定。
  • 后续登录时,通过返回的appleCredential.userIdentifier,从你的存储系统中查询对应的用户信息,不再依赖Apple Sign In返回的邮箱和全名字段。
  • 特殊场景处理:若用户后续在Apple账户中修改了邮箱,Apple不会主动推送变更通知到应用,你可以提供用户手动更新入口,或定期通过Apple的验证接口同步信息(该场景出现概率较低)。

你的实现代码

String generateNonce([int length = 32]) {
  final charset =
      '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
  final random = Random.secure();
  return List.generate(length, (_) => charset[random.nextInt(charset.length)])
      .join();
}

/// Returns the sha256 hash of [input] in hex notation.
String sha256ofString(String input) {
  final bytes = utf8.encode(input);
  final digest = sha256.convert(bytes);
  return digest.toString();
}

final rawNonce = generateNonce();
final nonce = sha256ofString(rawNonce);

final appleCredential = await SignInWithApple.getAppleIDCredential(
  scopes: [
    AppleIDAuthorizationScopes.email,
    AppleIDAuthorizationScopes.fullName,
  ],
  nonce: nonce,
);

final oauthCredential = OAuthProvider("apple.com").credential(
  idToken: appleCredential.identityToken,
  rawNonce: rawNonce,
);

final authResult = await _firebaseAuth.signInWithCredential(oauthCredential);

return authResult;

内容的提问来源于stack exchange,提问作者Dipendra Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 19:25:27