C# Swagger generated client with domain authentication

Viewed 144

We have a simple rest API exposed with Swagger UI. We usually copy-paste the raw definition to editor.swagger.io, and generate a C# client. The generated code works very well - but we work in a Windows AD environment, and we cannot find any way to tell the client to use the current user credentials during the communication. So the IIS hosted rest API throws Unauthorized exception - as it is set to Windows authentication mode.

Is it possible to use the generated client this way? Any option to add to the API definition to generate such a client?

Writing a client manually is easy:

var client = new WebClient();
client.UseDefaultCredentials = true;
...

but we would like to generate it ... but the Configuration contains nothing about credentials ... :(

public static IO.Swagger.Api.IBookingApi GetBookingApiWebApi()
{
    var basePath = ConfigurationManager.AppSettings["web.api.url"];
    var api = new BookingApi(basePath);
    return api;
}

Thanks in advance...

0 Answers
Related