在本地运行时,如何在 Azure 静态网站托管(预览版)中传递"x-ms-client-principal"?



我正在尝试新的 Azure 静态网站托管预览版,在本地运行时,Azure 函数在 req 绑定对象中未收到"x-ms-client-principle"标头。

我的路由文件如下所示:

{
"routes": [
{
"route": "/api/*",
"allowedRoles": ["administrator"]
},
{
"route": "/*",
"serve": "/index.html",
"statusCode": 200
}
]
}

我的 API 函数在以下位置被击中:/api/message,但不包括标头。

module.exports = async function (context, req) {
const header = req.headers["x-ms-client-principal"]; // req.headers doesn't include x-ms-client-principle
const encoded = Buffer.from(header, "base64");
const decoded = encoded.toString("ascii");
}

静态应用程序是使用 create-react-app 创建的 React 静态页面。我有一行可以从反应应用程序打印出结果:

fetch(`${process.env.REACT_APP_API}/message?name=me`)
.then(a => a.text())
.then(console.log);

本地process.env.REACT_APP_API通过REACT_APP_API=http://127.0.0.1:7071/api设置。

API 受到攻击,但我不确定它是否运行正确版本的 Azure Functions。它正在报告:Function Runtime Version: 2.0.12961.0即使我已经安装了 azure-functions-core-tools@3,并在settings.json中设置了正确的值 ("azureFunctions.projectRuntime": "~3"(。

我的问题是我错过了什么,如果是,那是什么?

目前,这似乎不是受支持的方案:

https://github.com/MicrosoftDocs/azure-docs/issues/55517

对于任何偶然发现 2022 年的人,都有一个 CLI,请记住正确设置 api。虽然设置起来并不容易,但它可以工作。

最新更新