Describe the bug
In some scenarios, a service can support both authenticated and unauthenticated requests.
If I have a service namespace with the following:
@useAuth(
NoAuth | OAuth2Auth<[
{
type: OAuth2FlowType.implicit,
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize",
scopes: ["https://monitor.azure.com/.default"],
}
]>
)
The http-client-csharp emitter will emit a client where TokenCredential is required. Example constructor:
public ApplicationInsightsClient(Uri endpoint, TokenCredential credential, ApplicationInsightsClientOptions options)
{
Argument.AssertNotNull(endpoint, nameof(endpoint));
Argument.AssertNotNull(credential, nameof(credential));
options ??= new ApplicationInsightsClientOptions();
_endpoint = endpoint;
_tokenCredential = credential;
Pipeline = HttpPipelineBuilder.Build(options, new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) });
_apiVersion = options.Version;
ClientDiagnostics = new ClientDiagnostics(options, true);
}
The emitter will also give the warning: main.tsp:28:11 - warning @typespec/http-client-csharp/unsupported-auth: un-supported authentication scheme noAuth
Can we make it so that the credential doesn't need to be specified for unauthenticated requests? Similar issue in the python emitter: #9238
Reproduction
Using the http-client-csharp emitter with:
@useAuth(
NoAuth | OAuth2Auth<[
{
type: OAuth2FlowType.implicit,
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize",
scopes: ["https://monitor.azure.com/.default"],
}
]>
)
@service(#{ title: "Azure Monitor Exporter" })
@versioned(Versions)
@server(
"{host}/{apiVersion}",
"Azure MonitorOpenTelemetry Exporter Service",
{
/** Application Insights' Breeze endpoint. */
host: url = "https://dc.services.visualstudio.com",
/** The service API version. */
apiVersion: Versions,
}
)
namespace AzureMonitorExporter;
Checklist
Describe the bug
In some scenarios, a service can support both authenticated and unauthenticated requests.
If I have a service namespace with the following:
The
http-client-csharpemitter will emit a client where TokenCredential is required. Example constructor:The emitter will also give the warning:
main.tsp:28:11 - warning @typespec/http-client-csharp/unsupported-auth: un-supported authentication scheme noAuthCan we make it so that the credential doesn't need to be specified for unauthenticated requests? Similar issue in the python emitter: #9238
Reproduction
Using the
http-client-csharpemitter with:Checklist