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

Firebase通过Twitch OpenID Connect登录后用户Identifier为空问题排查

Twitch OIDC登录Firebase后用户Identifier字段为空的解决办法

问题核心在于Twitch的OIDC默认不会返回用户邮箱信息,而Firebase的Identifier字段依赖该信息填充,需要补充权限请求和配置:

  • 添加邮箱读取权限
    Twitch要求显式申请user:read:email权限才能获取用户邮箱,修改你的登录代码,在provider中添加该范围:
// TWITCH SIGN IN HANDLER
const twitchsigninBtn = document.getElementById('twitchsigninBtn');

var provider = new firebase.auth.OAuthProvider('oidc.twitch');

// 新增:请求Twitch邮箱读取权限
provider.addScope('user:read:email');

// Twitch Custom Parameters:
provider.setCustomParameters({
        force_verify: 'true'
      });

// Twitch Login function
twitchsigninBtn.onclick = () => {
firebase.auth().signInWithPopup(provider)
  .then((result) => {
    // 可打印profile确认是否返回邮箱
    console.log(result.additionalUserInfo.profile);
    
    /** @type {firebase.auth.OAuthCredential} */
    var credential = result.credential;
    var accessToken = credential.accessToken;
    var idToken = credential.idToken;
  })
  .catch((error) => {
    // Handle error.
  });
}
  • 检查Firebase OIDC配置
    登录Firebase控制台,进入你配置的Twitch OIDC提供商页面,确保在"范围"字段中添加了user:read:email,让Firebase在认证流程中自动请求该权限。

  • 手动同步邮箱(可选)
    如果Firebase仍未自动填充Identifier,可在登录成功后手动将Twitch返回的邮箱更新到Firebase用户:

.then((result) => {
  const user = result.user;
  const profileEmail = result.additionalUserInfo.profile.email;
  
  if (profileEmail && user.email !== profileEmail) {
    user.updateEmail(profileEmail)
      .then(() => {
        // 邮箱更新完成,Identifier字段会同步更新
      })
      .catch((error) => {
        // 处理更新失败的情况,比如用户已存在该邮箱
      });
  }
})

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 05:05:13