Repository navigation
[http-client-js] Make credential optional when NoAuth is part of the auth union - #12583
Open
Mohammad Malik (mohammad-malik) wants to merge 2 commits into
Conversation
Mohammad Malik (mohammad-malik)
requested review from
Mary Gao (MaryGao),
catalinaperalta,
iscai-msft,
Laurent Mazuel (lmazuel),
Maor Leger (maorleger),
Mark Cowlishaw (markcowl),
Qiaoqiao Zhang (qiaozha),
Timothee Guerin (timotheeguerin) and
Jeff Fisher (xirzec)
as code owners
November 13, 2026 23:40
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The credential remains incorrectly required when every operation permits anonymous access because the check uses the namespace authentication default instead of effective per-operation requirements.
1 open issue
What changed in this PR
Updates the JavaScript HTTP client emitter to support anonymous calls when authentication allows NoAuth, addressing #12354. It also fixes credential-type reuse in the shared HTTP client helpers.
Changes:
- Makes eligible credentials optional while keeping them positional before
options. - Distinguishes HTTP authentication schemes in the credential cache.
- Adds an anonymous-auth scenario, corrects bearer expectations, and records both fixes in changelogs.
| File | Description |
|---|---|
packages/http-client/src/utils/client-helpers.ts |
Includes HTTP scheme names in credential cache keys. |
packages/http-client-js/test/scenarios/auth/no_auth_union.md |
Adds optional-credential constructor and context expectations. |
packages/http-client-js/test/scenarios/auth/client_structure.md |
Corrects the expected credential type to bearer. |
packages/http-client-js/test/scenarios/auth/bearer.md |
Corrects bearer constructor and context expectations. |
packages/http-client-js/src/utils/parameters.tsx |
Determines credential optionality and preserves positional ordering. |
.chronus/changes/http-client-js-noauth-optional-credential-2026-10-13-23-40-0.md |
Documents optional credentials for anonymous access. |
.chronus/changes/http-client-fix-credential-cache-key-2026-10-13-23-45-0.md |
Documents the credential cache correction. |
Review effort: Balanced
| } | ||
|
|
||
| const auth = $.client.getAuth(client); | ||
| return [auth.defaultAuth, ...auth.operationsAuth.values()].every(allowsAnonymousAccess); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #12354
With
@useAuth(BearerAuth | NoAuth), the JS client emitter generated a requiredcredentialparameter, so there was no way to call the service anonymously. The Python emitter already handles this (#9298).Changes:
http-client-js(utils/parameters.tsx): the credential is optional whenNoAuthis an alternative for every operation of the client. An optional credential stays positional, after the required parameters and beforeoptions. A parent client that requires auth still gets a required credential even if a nested namespace usesNoAuth(covered by the existingsub_client_override.md).http-client(utils/client-helpers.ts): the synthetic credential parameter was cached by scheme type only, soBearerAuthandBasicAuthcould share one cache entry and produce the wrong credential type depending on test order. The cache key now includes the http scheme. I updatedbearer.mdandclient_structure.md, which had been expectingBasicCredentialforBearerAuth.test/scenarios/auth/no_auth_union.md.No runtime change is needed: with
credential: undefined,getClientfrom@typespec/ts-http-runtimeadds no auth policy and sends noAuthorizationheader.Tests pass in
http-client-js(248 passed) andhttp-client(46 passed), and lint and prettier are clean.