如何将 Firebase AppCheck 与 httpsCallable 函数结合使用?

问题描述 投票:0回答:1

我正在使用 firebase 函数,就像这样......

exports.sendLicenseAgain = onCall({
  enforceAppCheck: true,
  consumeAppCheckToken: true,
}, async (req) => {
     ...
})

我的 Angular 17 前端代码中有这个

import { getFunctions, httpsCallable } from 'firebase/functions';
import { AppCheck, getToken } from '@angular/fire/app-check';
....
...
getToken(this.appCheck).then((token) => {
        const funcs = getFunctions();
        const sendFunc= httpsCallable(funcs, "sendLicenseAgain", { limitedUseAppCheckTokens: true })
        sendFunc({ ... })

我收到错误状态 401,因为我没有包含 appcheck 令牌。我知道我应该将令牌放在 http 请求中带有“X-Firebase-AppCheck”的标头中,但我找不到使用 httpsCallable 函数来做到这一点的方法。我是不是错过了什么?

angular firebase google-cloud-functions firebase-app-check angular-standalone-components
1个回答
0
投票

如果您使用 Firebase 客户端库进行调用,则无法控制可调用函数的 HTTP 标头。

要将 App Check 与可调用类型函数一起使用,您不必对标头执行任何操作,因为库会为您处理标头。详情请参阅文档

© www.soinside.com 2019 - 2024. All rights reserved.