3

I need to Authorize in the Swagger UI once by hitting Authorize Button. Is it possible to switch between different swagger endpoints and have token pre-set on all of them? Now it doesn't understand I already authenticated or loses received token on different Swagger endpoint / definition.

I configure SecurityDefinitions/SecurityRequirements once via AddSwaggerGen method. Then I add multiple endpoints in UseSwaggerUI:

app.UseSwaggerUI(c =>
{
  groupNames.ForEach(groupName => c.SwaggerEndpoint(
    $"/swagger/{groupName}/swagger.json", $"API Name - {groupName}"));
});
  • What auth type do your APIs use (e.g. Bearer, API key, Basic, OAuth 2)? Do all APIs (i.e. different OpenAPI definitions) use the same auth type or different auth types? Swagger UI has [`preauthorize*`](https://stackoverflow.com/a/50181701/113116) methods, but I'm not sure if they preserve the authentication status and tokens when switching between definitions. – Helen Dec 23 '21 at 21:40
  • My API has 2 auth types - Bearer and OAuth 2, all API defs use the same 2 auth types. I don't have any info for preauthorize (want my API user to supply credentials online), so that's probably is not the case for me. All I need here is to make sure different definitions share the same token. – Nikolay Badin Dec 24 '21 at 21:32
  • Depends on your way of authentication. Swagger itself acts just as a client. In case you use JWT -> check the scope of your token. This is not an issue you can solve in swagger, but in your backend's configuration. – simUser Jan 03 '22 at 11:54

0 Answers0