5

I'm trying out the new Azure Static Website Hosting Preview and when running locally, the Azure functions aren't receiving the "x-ms-client-principle" header in the req binding object.

My routes file looks like:

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

My API function is getting hit at: /api/message, but isn't including the header.

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");
}

The static app is a React static page created with create-react-app. I have a line to print out the result from the react-app:

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

Locally process.env.REACT_APP_API is set via REACT_APP_API=http://127.0.0.1:7071/api.

The API is getting hit, but I'm not sure if it's running the correct version of Azure Functions. It is reporting: Function Runtime Version: 2.0.12961.0 even though I've installed azure-functions-core-tools@3, and set the proper value ("azureFunctions.projectRuntime": "~3") in settings.json.

My question is am I missing something, and if so, what?

Orion Adrian
  • 19,053
  • 13
  • 51
  • 67
  • What is 'x-ms-client-principle' refer to? I know `X-MS-CLIENT-PRINCIPAL-NAME` or 'X-MS-CLIENT-PRINCIPAL-ID'. – Tony Ju Jun 01 '20 at 01:28
  • x-ms-client-principle comes from the howto at: https://learn.microsoft.com/en-us/azure/static-web-apps/user-information#api-functions – Orion Adrian Jun 01 '20 at 01:55
  • Have your configured authentication? https://learn.microsoft.com/en-us/azure/static-web-apps/authentication-authorization – Tony Ju Jun 01 '20 at 02:07
  • I have, but I'm not sure how it's supposed to actually do the authentication running locally. – Orion Adrian Jun 01 '20 at 02:44

2 Answers2

2

For the moment, it appears that this is not a supported scenario per:

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

Orion Adrian
  • 19,053
  • 13
  • 51
  • 67
0

For anybody stumbling on this one 2022 there's a CLI and remember to set the api correctly.. Although not trivial to setup it works.

noontz
  • 1,782
  • 20
  • 29