Flutter与Firebase集成Apple登录时,如何保存私密中继邮箱?
解决方案
必须请求邮箱权限
发起Apple登录时,要明确声明email权限范围。使用sign_in_with_apple包的话,代码里需包含该权限:final credential = await SignInWithApple.getAppleIDCredential( scopes: [ AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName, ], );处理Apple返回的中继邮箱
Apple返回的私密中继邮箱会存在credential.email字段里,要把这个值和Firebase认证凭证一起提交,确保Firebase能捕获到该信息。检查Apple开发者后台配置
登录Apple开发者后台,找到应用对应的标识符,开启「私密中继邮箱」功能,配置好关联的域名和接收邮箱;同时确认Firebase控制台的Apple登录配置中,相关权限选项已正确启用。注意首次登录限制
Apple只会在用户首次授权登录时返回完整的邮箱信息,后续登录仅返回用户ID。测试时需要先在设备「设置」→「Apple ID」→「密码与安全性」→「使用Apple ID的应用」中取消对当前应用的授权,再重新登录测试。手动同步到Firebase用户信息
登录完成后,可手动将获取到的中继邮箱更新到Firebase用户信息中,确保字段持久化:final currentUser = FirebaseAuth.instance.currentUser; if (currentUser != null && credential.email != null) { await currentUser.updateEmail(credential.email!); }
内容的提问来源于stack exchange,提问作者kris
相关产品推荐
相关产品推荐

