Skip to content

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

Open

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.<anonymous> (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:215:46)
    at Generator.next (<anonymous>)
    at /home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:121:71
    at new Promise (<anonymous>)
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions