Firebase admin().auth().getUser(uid) 错误:发生内部错误“auth/internal-error" [英] Firebase admin().auth().getUser(uid) Error: An internal error has occurred 'auth/internal-error'

查看:25
本文介绍了Firebase admin().auth().getUser(uid) 错误:发生内部错误“auth/internal-error"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在节点服务器上使用 firebase-admin

I'm using firebase-admin on a node server

初始化管理应用程序正常:

Initializing the admin app works fine:

const admin = require('firebase-admin')
const serviceAccount = require('../service-account.json')
admin.initializeApp({                                                                                             
  credential: admin.credential.cert(serviceAccount),
  databaseURL: // firebaseio.com url
})

admin.auth().verifyIdToken(token).then((decoded) => {
  // THIS WORKS SUCCESS! a decoded token
  console.log('decoded', decoded)
  // now look up the user information
  admin.auth().getUser(decoded.uid).then((userRecord) => {
    console.log('got user record', userRecord)
  }).catch((err) => {
    // { [Error: An internal error has occurred.]
    //     errorInfo: 
    //      { code: 'auth/internal-error',
    //         message: 'An internal error has occurred.' } }
    console.error(err)
  })
})

getUser 的最后一部分因

{ [错误:发生内部错误.]错误信息:{ 代码:'身份验证/内部错误',消息:发生内部错误."} }

{ [Error: An internal error has occurred.] errorInfo: { code: 'auth/internal-error', message: 'An internal error has occurred.' } }

<小时>

当我尝试以另一种推荐的方式传递凭证时,我得到了这个:


When I tried to pass in the credential the other recommended way, I got this:

const admin = require('firebase-admin')
admin.initializeApp({                                                                                             
  credential: admin.credential.cert({
    projectId: //projectid,
    clientEmail: //client email,
    privateKey: //admin private key
  }),
  databaseURL: // firebaseio.com url
})

然后当我尝试验证和查找用户时:

Then when I try to verify and look up a user:

admin.auth().verifyIdToken(token).then((decoded) => {
  // THIS WORKS SUCCESS! a decoded token
  console.log('decoded', decoded)
  // now look up the user information
  admin.auth().getUser(decoded.uid).then((userRecord) => {
    console.log('got user record', userRecord)
  }).catch((err) => {
    // Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    console.error(err)
  })
})

getUser 的最后一部分因

错误:错误:0906D06C:PEM 例程:PEM_read_bio:没有起始行

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

推荐答案

这里的问题是正在使用的服务帐户没有明确的项目权限来下载用户.

The problem here is that the service account being used did not have explicit permissions on the project to download users.

事实证明,解码令牌只需要服务帐户,但其他操作如 getUser(uid)

Turns out, the service account alone is all that is needed to decode tokens, but extra permissions are required for other operations like getUser(uid)

要解决此问题,我必须进入项目权限中的 IAM 部分,并添加具有适当权限的服务器帐户的电子邮件地址(我做了编辑).

To fix this, I had to go into the IAM section in the permissions on the project and add the email address for the server account with the appropriate permissions (I did editor).

步骤

  • 设置图标 -> 权限
  • IAM
  • + 添加用户图标
  • 输入服务帐户凭据的电子邮件地址并分配角色

这篇关于Firebase admin().auth().getUser(uid) 错误:发生内部错误“auth/internal-error"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆