Forum Discussion

galfven's avatar
galfven
New Contributor
2 years ago

Need to send header with Basic Auth

Hello ladies and gentlemen!
I'm new to Swagger when it comes to implementing it for my own api:s.
Today I have gone from being a complete fool to just being dumb. 🙂
I managed to make the "Try it out" button actually appear. It took me about two hours to finally find information on why it was not visible in my project.
Then I managed to also make the Authorize button to show up. And I can select the authorization method and input my user id and password.
But. (there's always a but right?)
It does not seem as if the Basic Auth is sent in the header. I have tried every single suggestion I have found after Googling and consulting ChatGPT. Nothing seems to get me any closer to a solution.
It's so easy to use Postman to send the queries to the same api, but with Swagger I have unfortunately hit the wall too many times, so I consult you guys. The crème de la crème of Swaggerians... what am I missing?

I have this in my Startup.cs - did I mention that this is an ASP.Net Core 3.1 Web Api? And that I'm using the latest stable versions of everything that has to do with Swagger.

options.AddSecurityDefinition("Basic", new OpenApiSecurityScheme
{
   Type = SecuritySchemeType.Http,
   Scheme = "basic",
   In = ParameterLocation.Header,
   Name = "Authorization",
   Description = "Basic Authorization header."

});
options.OperationFilter<SecurityRequirementsOperationFilter>();


Where on earth I got that piece of probably old code? From ChatGPT. Not to be trusted. I know.

By the way, I must mention that I don't know the first thing about which label to choose for this post.
I'll go with Swagger Core and Swagger UI, but maybe both are wrong. Sorry about that.

I guess you need more information - just tell me, and I'll provide all details needed.


Best regards,
George




  • In case someone hits the wall as hard as I did:
    This did the trick for me:

    Type = ReferenceType.SecurityScheme,

  • galfven's avatar
    galfven
    New Contributor

    In case someone hits the wall as hard as I did:
    This did the trick for me:

    Type = ReferenceType.SecurityScheme,