Skip to content

fix(typespec-js): allow optional credential in useAuth union - #12396

Closed
Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 1 commit into
microsoft:mainfrom
Hrushikesh-ramilla:fix/http-client-js-no-auth-union
Closed

Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 1 commit into
microsoft:mainfrom
Hrushikesh-ramilla:fix/http-client-js-no-auth-union

Conversation

@Hrushikesh-ramilla

@Hrushikesh-ramilla Hrushikesh Ramilla (Hrushikesh-ramilla) commented Oct 25, 2026 •

Copy link
Copy Markdown

Allow optional credential in useAuth union.

…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
@azure-pipelines

Copy link
Copy Markdown
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.

@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler emitter:client:js Issue for the JS client emitter: @typespec/http-client-js auto-merge Automatically merge the pull request after all requirements pass labels Oct 25, 2026

@microsoft-github-policy-service microsoft-github-policy-service Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved automatically for a Dependabot update.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 NoAuth and excludes NoAuth from 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);
@Hrushikesh-ramilla Hrushikesh Ramilla (Hrushikesh-ramilla) closed this by deleting the head repository Oct 26, 2026
@Hrushikesh-ramilla Hrushikesh Ramilla (Hrushikesh-ramilla) changed the title fix(http-client-js): allow optional credential when NoAuth is in @useAuth union . Oct 29, 2026
@Hrushikesh-ramilla Hrushikesh Ramilla (Hrushikesh-ramilla) changed the title . fix(typespec-js): allow optional credential in useAuth union Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Automatically merge the pull request after all requirements pass compiler:core Issues for @typespec/compiler emitter:client:js Issue for the JS client emitter: @typespec/http-client-js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants