ttu / dotnet-fake-json-server

Fake JSON Server is a Fake REST API that can be used as a Back End for prototyping or as a template for a CRUD Back End.
https://ttu.github.io/dotnet-fake-json-server/
MIT License
388 stars 84 forks source link

Broken Auth in Swagger UI #71

Closed 5wdgJibXS7DEE closed 3 years ago

5wdgJibXS7DEE commented 4 years ago

On branch update-to-core-30 the endpoints under Authentification tag in Swagger UI are unusable with various symptoms on the following browsers :

Those endpoints work fine with cURL commands. The problem comes from Swagger UI.

Note: on branch master with .NET Core 2.2, despite the web browser receives the auth token, the Swagger UI does not display the response. Is it important to fix that, or should we focus our effort on .NET Core 3?

5wdgJibXS7DEE commented 4 years ago

Indeed Swagger UI do not respond well to the way the swagger.json file was generated with the use of AddAuthorizationHeaderParameterOperationFilter and/or AuthTokenOperation as you guessed correctly.

In order to make sure of that, I tested Swagger UI with a swagger.json I created manually. The UI works fine:

They are changes in the UI/UX:

My point of view is that this change is for the best. It simplifies the use of the API for testing. Here is a screenshot:

image

After a quick read of Swashbuckle docs I think I can generate a similar swagger.json using AddSecurityRequirement in configuration.

@ttu Is it fine for you if I go this way?

ttu commented 4 years ago

Thanks for the inspecting the issue.

Using AddSecurityDefinition is the normal way to add authentication to Swagger. Not sure why I didn't go that way in the beginning. Maybe wanted to have authentication endpoints visible from Swagger so it is more clear for people who are not familiar with Swagger what kind of functionality backend provides. Or just couldn't get it working any other way... Can't be sure anymore 😄

Yes, try to add authentication by configuring Swashbucle 👍 . Logout endpoint might still be needed as blacklisting the tokens is a custom functionality. Swagger logout doesn't call that endpoint by default.

5wdgJibXS7DEE commented 4 years ago

@ttu I let you know that I'll have time to work on it this week-end :)

ttu commented 3 years ago

Fixed in https://github.com/ttu/dotnet-fake-json-server/commit/e236100db243d8501e34d5e50818c73bbfd92c65