【发布时间】:2020-06-03 00:02:46
【问题描述】:
我正在试用新的 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 静态页面。我有一行打印出 react-app 的结果:
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")。
我的问题是我错过了什么,如果有,是什么?
【问题讨论】:
-
“x-ms-client-principle”指的是什么?我知道
X-MS-CLIENT-PRINCIPAL-NAME或“X-MS-CLIENT-PRINCIPAL-ID”。 -
x-ms-client-principle 来自 howto:docs.microsoft.com/en-us/azure/static-web-apps/…
-
我有,但我不确定它应该如何实际执行本地运行的身份验证。
标签: reactjs azure azure-functions azure-static-website-hosting