我有一个函数,它有一些代码来检查用户是否经过身份验证
export const addAffiliate = functions.region('us-central1').https.onCall(
async (inputData: any, context: functions.https.CallableContext) => {
checkAuthentication(context);
...
export const checkAuthentication = (
context: functions.https.CallableContext
) => {
// Checking that the user is authenticated.
if (!context.auth) {
// Throwing an HttpsError so that the client gets the error details.
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called ' + 'while authenticated.'
);
}
};
gcloud auth print-identity-token
命令,将其粘贴到带有“bearner”+token值的授权头中,并调用它以获得成功的响应。
checkAuthentication
方法。它只是立即返回未经验证的响应(401)。我不提供身份验证头的工作流工作正常,我得到了400个。只有在auth头中提供一些垃圾值时,才能在本地重现这种行为。
{
"error": {
"message": "Unauthenticated",
"status": "UNAUTHENTICATED"
}
}