【发布时间】:2020-03-06 08:51:22
【问题描述】:
我有一个 Firebase 应用,我正在集成 Zapier。他们要求用户通过他们的表单对我的应用进行身份验证。
它的工作方式是 Zapier 将向用户请求电子邮件和密码并将其发送到我的端点以获取访问令牌并将其用于任何进一步的请求。
我不太清楚如何从服务器(节点 js)上的用户名和密码生成访问令牌,因为所有身份验证方法都存在于客户端 SDK 中。
到目前为止,我希望使用提供的电子邮件/密码对用户进行身份验证,从他们的uid 生成自定义令牌并将其发送回 Zapier。但我不能这样做,因为服务器 SDK 中没有 signInWithEmailAndPassword 或类似方法。
我知道我可以通过电子邮件获取用户,但是我如何检查密码,因为相应的方法再次仅在客户端 SDK 中可用?
到目前为止,我得到了以下代码:
const rp = require('request-promise');
app.post('/api/integrations/zapier/auth', (req, res) => {
let data = req.body
admin.auth().signInWithEmailAndPassword(data.email, data.password) // <- this method doesn't exist in the server sdk
.then(response => admin.auth().createCustomToken(response.user.id))
.then(customToken => rp({
url: `https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=${config.apiKey}`,
method: 'POST',
body: {
token: customToken,
returnSecureToken: true
},
json: true,
}))
.then(idToken => {
res.send({
accessToken: idToken,
filed: data.email
});
}).catch(error => res.status(500).send(error));
})
【问题讨论】:
标签: javascript firebase firebase-authentication firebase-admin