Skip to content

Allow App Service callers without a principal name - #479

Open
Hyun Lee (dlwhdgus0810) wants to merge 1 commit into
Azure:v4.xfrom
dlwhdgus0810:fix-374-missing-principal-name
Open

Hyun Lee (dlwhdgus0810) wants to merge 1 commit into
Azure:v4.xfrom
dlwhdgus0810:fix-374-missing-principal-name

Conversation

@dlwhdgus0810

Copy link
Copy Markdown

Fixes #374

Problem

App Service Authentication sends no x-ms-client-principal-name header when the caller has no name claim. A service principal that calls the API with a client credentials token is one such caller. The other headers are still sent: x-ms-client-principal-id, x-ms-client-principal-idp and x-ms-client-principal.

extractHttpUserFromHeaders required the name header through nonNullValue, so reading request.user threw:

AzFuncSystemError: Internal error: Expected value to be neither null nor undefined: user-name

Changes

  • The AppService branch uses an empty username when x-ms-client-principal-name is missing. The id and identity provider headers are still required.
  • The username doc comment in types/http.d.ts says when it is empty.

The type stays string, so existing code keeps compiling. username?: string would describe the service principal case more exactly, but it changes the public type. I can switch to that if you prefer it.

Testing

  • New test in test/http/extractHttpUserFromHeaders.test.ts: AppService headers without x-ms-client-principal-name give an AppService user with an empty username. Without the change, the test fails with the error above.
  • npm test: 463 passing.
  • eslint, prettier --check and npm run build pass.

App Service Authentication sends no x-ms-client-principal-name header
when the caller has no name claim, as with a service principal. Reading
request.user then threw an internal error. The username is now empty
for such callers.

Fixes Azure#374
@dlwhdgus0810
Hyun Lee (dlwhdgus0810) requested a review from a team as a code owner September 30, 2026 04:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dlwhdgus0810

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant