Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/specs-noAuth-2026-0-6-16-4-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add test for services that accept `NoAuth` unioned with other auth type
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ words:
- nexted
- nihao
- nint
- noauth
- NODEFS
- noformat
- nologo
Expand Down
12 changes: 12 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ Expect error code 403 and error body:

Expects header 'Authorization': 'SharedAccessKey valid-key'

### Authentication_Noauth_Union_validNoAuth

- Endpoint: `get /authentication/noauth/union/valid`

Expects no authentication. The server accepts requests without any authentication header.

### Authentication_Noauth_Union_validToken

- Endpoint: `get /authentication/noauth/union/validtoken`

Expects header 'authorization': 'Bearer https://security.microsoft.com/.default'

### Authentication_OAuth2_invalid

- Endpoint: `get /authentication/oauth2/invalid`
Expand Down
30 changes: 30 additions & 0 deletions packages/http-specs/specs/authentication/noauth/union/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "@typespec/http";
import "@typespec/spector";

using Http;
using Spector;

@scenarioService("/authentication/noauth/union")
@doc("Illustrates clients generated with NoAuth and OAuth2 authentication union.")
@useAuth(NoAuth | OAuth2Auth<[MyFlow]>)
namespace Authentication.Noauth.Union;

model MyFlow {
type: OAuth2FlowType.implicit;
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize";
scopes: ["https://security.microsoft.com/.default"];
}

@scenario
@scenarioDoc("Expects no authentication. The server accepts requests without any authentication header.")
@doc("Check whether client can make a request without authentication")
@get
@route("/valid")
op validNoAuth(): NoContentResponse;

@scenario
@scenarioDoc("Expects header 'authorization': 'Bearer https://security.microsoft.com/.default'")
@doc("Check whether client is authenticated with OAuth2 token")
@get
@route("/validtoken")
op validToken(): NoContentResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Scenarios.Authentication_Noauth_Union_validNoAuth = passOnSuccess({
uri: `/authentication/noauth/union/valid`,
method: "get",
request: {},
response: {
status: 204,
},
kind: "MockApiDefinition",
});

Scenarios.Authentication_Noauth_Union_validToken = passOnSuccess({
uri: `/authentication/noauth/union/validtoken`,
method: "get",
request: {
headers: {
authorization: "Bearer https://security.microsoft.com/.default",
},
},
response: {
status: 204,
},
kind: "MockApiDefinition",
});
Loading