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

在Firebase网站启用Sign in with Apple时遇配置及授权问题

问题解决指南:Firebase + Apple登录配置及代码错误排查

一、Apple开发者平台Service ID配置问题(No App ID is available/按钮灰色)

出现"No App ID is available"且Next/Done按钮不可用,核心原因是Service ID必须关联一个已启用「Sign in with Apple」的App ID,修正步骤如下:

  1. 先创建并配置App ID:
    • 进入Certificates, Identifiers & Profiles → Identifiers → 点击「+」
    • 选择「App IDs」,填写描述、Bundle ID,勾选「Sign in with Apple」后点击「Configure」
    • 在App ID的Sign in with Apple配置弹窗中,选择「Enable as Primary App ID」,完成后保存并返回
  2. 回到Service ID配置流程:
    • 重新进入Service ID的「Sign in with Apple」配置弹窗,此时会出现可选择的App ID,选中关联
    • 填写「Domains and Subdomains」(你的自定义域名,不带https前缀)
    • 填写「Return URLs」:包含Firebase默认回调URL和自定义域名回调URL,格式为https://<项目ID>.firebaseapp.com/__/auth/handler和https://<自定义域名>/__/auth/handler
    • 此时弹窗会出现「Done」按钮,完成配置后Next按钮即可点击

二、代码中auth/operation-not-allowed错误及跳转无响应问题

1. 错误根源排查

auth/operation-not-allowed通常是以下原因:

  • Firebase控制台未启用Apple登录提供商
  • Apple开发者平台的Return URLs未包含正确的Firebase回调地址
  • 代码中Auth实例使用不一致

2. 代码修正

你的appleAuth方法存在Auth实例重复调用的问题,统一使用注入的this.auth,同时添加必要的权限范围:

import { OAuthProvider } from '@angular/fire/auth'; // 补充导入OAuthProvider
// ...其他导入

async appleAuth() {
  if (this.auth) {
    const provider = new OAuthProvider('apple.com');
    // 添加获取用户邮箱、姓名的权限(按需配置)
    provider.addScope('email');
    provider.addScope('name');
    // 使用注入的Auth实例,避免重复调用firebase.getAuth()
    await signInWithRedirect(this.auth, provider);
    // 注意:signInWithRedirect不会立即返回结果,需在页面初始化时调用getRedirectResult
    // 示例:在组件的ngOnInit中
    // const result = await getRedirectResult(this.auth);
    // if (result) { /* 处理登录结果逻辑 */ }
    return firstValueFrom(this.isLoggedIn!);
  }
  return false;
}

3. 额外配置检查

  • 登录Firebase控制台 → 认证 → 登录方法,确认「Apple」已启用,且填写了正确的Service ID、Team ID、私钥等信息
  • 确认Firebase控制台 → 认证 → 设置 → 授权域名中,已添加你的自定义域名
  • 确保Apple开发者平台中,Service ID的「Sign in with Apple」配置里的Return URLs包含所有需要的回调地址(默认Firebase域名+自定义域名的auth handler)

三、自定义域名冲突处理

如果自定义域名导致Google登录正常但Apple登录异常,需确保:

  • Apple侧的「Domains and Subdomains」填写自定义域名(如yourdomain.com,不带https)
  • Apple侧的Return URLs同时包含默认Firebase回调URL和自定义域名回调URL
  • Firebase Auth的授权域名列表中已添加自定义域名

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 20:08:29