Repository navigation
fix(typespec-js): allow optional credential in useAuth union - #12396
Closed
Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 1 commit into
Closed
Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 1 commit into
Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 1 commit into
Conversation
…Auth union (#12354) - Make credential parameter optional when NoAuth is included in an auth union - Filter out noAuth scheme in client context auth options - Fix scheme collision in getCredentialParameter credentialCache across programs - Fix Node 22 glob exclude callback type in test-host - Add scenario test verifying optional credential typing for auth union
Hrushikesh Ramilla (Hrushikesh-ramilla)
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
October 25, 2026 11:56
|
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. |
Copilot started reviewing on behalf of
Hrushikesh Ramilla (Hrushikesh-ramilla)
October 25, 2026 11:57
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Authentication optionality still misses effective requirements, and credential metadata sharing and parameter classification remain incorrect.
4 open issues
What changed in this PR
This PR addresses #12354 by allowing JavaScript clients to omit credentials when authentication includes a NoAuth alternative. It also improves shared credential caching and compiler test-host compatibility.
Changes:
- Makes credentials optional for default authentication unions containing
NoAuthand excludesNoAuthfrom runtime schemes. - Scopes credential caches per program and distinguishes authentication schemes.
- Adds scenario coverage, corrects bearer expectations, and updates glob exclusions for Node 22+.
| File | Description |
|---|---|
packages/http-client/src/utils/client-helpers.ts |
Adds per-program, scheme-qualified credential caching. |
packages/http-client-js/test/scenarios/auth/union_no_auth.md |
Adds optional-credential output expectations. |
packages/http-client-js/test/scenarios/auth/client_structure.md |
Corrects the expected bearer credential type. |
packages/http-client-js/test/scenarios/auth/bearer.md |
Corrects bearer constructor and factory expectations. |
packages/http-client-js/src/utils/parameters.tsx |
Determines credential optionality and retains positional credentials. |
packages/http-client-js/src/components/client-context/client-context-factory.tsx |
Filters NoAuth from runtime authentication schemes. |
packages/compiler/src/testing/test-host.ts |
Uses a callback for glob exclusions. |
.chronus/changes/fix-http-client-js-no-auth-union.md |
Records fixes for the three affected packages. |
Review effort: Balanced
| const { $ } = useTsp(); | ||
| const auth = $.client.getAuth(client); | ||
| const isAuthOptional = auth.defaultAuth.options.some((opt) => | ||
| opt.all.some((ref) => ref.auth.type === "noAuth"), |
Comment on lines
+18
to
+20
| const isAuthOptional = auth.defaultAuth.options.some((opt) => | ||
| opt.all.some((ref) => ref.auth.type === "noAuth"), | ||
| ); |
| } | ||
|
|
||
| if (!descriptor.optional) { | ||
| if (!descriptor.optional || descriptor.name === "credential") { |
Comment on lines
+43
to
44
| const credentialCache = getCredentialCache($.program); | ||
| const cacheKey = getCredRefkey(credTypes); |
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.

Allow optional credential in useAuth union.