Azure / Azure/azure-functions-nodejs-library

Exception when reading user property of request when authenticated with a service principal.

Open
#374 0 comments 3 reactions 0 assignees View on GitHub
area:nodejs-functions
Dominant language
TypeScript
Stars
70
Forks
35
Avg merge
4d 18h
Merged PRs (30d)
6

Description

I have an example project which illustrates the issue.

https://github.com/shaneholder/managed-identity-oauth
clone the repo
```
cd terraform
terraform apply --auto-approve
cd ../api
npm install
npm run deploy
cd ../client
npm install
node ./call.js
```

you'll see that the response has an error property populated with `{ isAzureFunctionsSystemError: true }`

in the console logs of the azure function app you will see.

```
Error reading user info: AzFuncSystemError: Internal error: Expected value to be neither null nor undefined: user-name
at nonNullValue (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:2791:15)
at extractHttpUserFromHeaders (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:2078:54)
at get user (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:1852:127)
at handler (file:///home/site/wwwroot/src/functions/user.js:31:24)
at InvocationModel. (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:215:46)
at Generator.next ()
at /home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:121:71
at new Promise ()
at __webpack_modules__../src/InvocationModel.ts.__awaiter (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:117:12)
at InvocationModel.invokeFunction (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:213:16) {
isAzureFunctionsSystemError: true
}
```
I believe this happens because the header `x-ms-client-principal-name` is not populated by Easy Auth when an API is called using a service principal and the code in extractHttpUserFromHeaders.ts is using the nonNullValue() function to verify the value is not null.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.