【发布时间】:2021-12-18 06:03:03
【问题描述】:
使用 Firebase Admin SDK 实现租户感知身份验证实例时,我无法使用 following method。
代码:
// defined elsewhere: locals.tenantAuth = getAuth().tenantManager().authForTenant(tenantId)
async createSession (locals) {
try {
const { idToken, expiresIn, tenantAuth } = locals
const decodedToken = await tenantAuth.verifyIdToken(idToken, true) // this works
// Only process if the user just signed in in the last 3 minutes
if (new Date().getTime() / 1000 - decodedToken.auth_time < 3 * 60) {
return await tenantAuth.createSessionCookie(idToken, { expiresIn }) // this breaks
} else {
throw new Error('Cannot create session, sign in information is too old')
}
} catch (error) {
console.log(error)
throw new Error(error)
}
}
错误:
FirebaseAuthError: This operation is not supported in a multi-tenant context.
errorInfo: {
code: 'auth/unsupported-tenant-operation',
message: 'This operation is not supported in a multi-tenant context.'
},
codePrefix: 'auth'
版本:
- Nodejs:16.13.0
- Firebase 管理员 SDK:10.0.0
补充:
- 方法在tenantAware 身份验证之外工作(使用默认项目
getAuth()) - v9 出现同样的错误
【问题讨论】:
标签: node.js firebase multi-tenant firebase-admin google-identity