【发布时间】:2019-07-16 07:31:39
【问题描述】:
所以我制作了这个非常简单的方法,我想使用自定义令牌登录到 Firebase。就目前而言,它只是
export const createCustomToken = functions.region('europe-west1').https.onCall(async (data, context) => {
try {
const firebaseJWT = await authenticationProvider.createCustomToken()
console.log(firebaseJWT.toString())
} catch (err) {
throw new functions.https.HttpsError('internal', 'Something went wrong ');
}
});
authenticationProvider 如下所示:
return firebase.admin.auth().createCustomToken("Some uid")
.then((token) => {
console.log("Did create custom token.");
return token;
}).catch((error) => {
console.log("Error creating custom token:" + error);
throw new firebase.functions.https.HttpsError('internal', 'createCustomToken(uid) has failed for some reason');
})
}
我尝试使用 shell 方法在本地运行它,在命令提示符下执行此行:firebase functions:shell 然后调用 authenticationController.createCustomToken({})
这只是给了我这个回应: 创建自定义令牌时出错:错误:无法确定服务帐户。确保使用服务帐户凭据初始化 SDK。或者,指定具有 iam.serviceAccounts.signBlob 权限的服务帐户。原始错误:错误:发出请求时出错:getaddrinfo ENOTFOUND 元数据元数据:80。错误代码:ENOTFOUND
服务帐户似乎具有正确的角色,所以我认为这不是问题。
所以我想知道是否有任何方法可以让我从 Postman 调用 createCustomToken() 函数,并查看响应以便我可以正确测试我的代码,而无需应用程序实现 onCall 方法来查看结果?
或者我缺少什么来通过 firebase 函数运行它:shell 命令?
【问题讨论】:
-
Postman 不会实现可调用对象在 HTTP 之上使用的协议:firebase.google.com/docs/functions/callable-reference
标签: firebase google-cloud-functions postman