Is it possible to enable a form for entering bearer tokens in Swagger-UI from ServiceStack's OpenApiFeature? This is possible in NSwag with their Swagger 2.0 implementation.
Asked
Active
Viewed 486 times
1 Answers
3
Support for being able to customize Security Definitions was added in this commit where you can specify that you want "Bearer" Api Key authentication with:
Plugins.Add(new OpenApiFeature
{
UseBearerSecurity = true,
});
If you want to revert to using HTTP Basic Auth Security use
UseBasicSecurity=true
This will customize the Open API metadata Response to specify your authenticated Services would like to use Swagger's API Key authentication, e.g:
As the value field is for the entire Authorization
HTTP Header you'd need to add your JWT Token or API Key prefixed with Bearer
:
Bearer {JWT or API Key}
This change is available from the latest v5.4.1 on MyGet, if you already have v5.4.1 installed you will need to clear your NuGet packages cache.

mythz
- 141,670
- 29
- 246
- 390
-
Seeing an error with the `ServiceStack.Api.OpenApi.Core` package: ```warn: ServiceStack.Host.Handlers.StaticFileHandler[0] Static File '/swaggerui/' not found in path: /swagger-ui/``` Should I report a bug somewhere? – yenta Jan 24 '19 at 13:33
-
@yenta I'm unable to repro it, but there shouldn't be any requests to `/swaggerui/` anywhere, the path to Swagger UI is `/swagger-ui/`, you can also click on the "Swagger UI" link in your metadata page. – mythz Jan 24 '19 at 23:27
-
the only difference i can find between 5.4.0 and 5.4.1 of `ServiceStack.Api.OpenApi.Core` is that the embedded resources in 5.4.0 have a prefix of `ServiceStack.Api.OpenApi` while the ones in 5.4.1 have a prefix of `ServiceStack.Api.OpenApi.Core` and that seems to be messing up the virtualfilehandler since the nameof(backingAssembly) is `ServiceStack.Api.OpenApi` – yenta Jan 25 '19 at 12:04
-
@yenta ok thx, this was due to moving to the [new build system](https://forums.servicestack.net/t/v5-4-1-now-hosting-source-link-enabled-packages/6728), I've just added `
` to all .Core.csproj's which now maintains embedded resources under the `ServiceStack.Api.OpenApi` namespace which is now available from the latest v5.4.1 on MyGet, as you already had v5.4.1 installed you'll need to [clear your NuGet packages cache](https://docs.servicestack.net/myget#redownloading-myget-packages). – mythz Jan 27 '19 at 21:48 -
1Thanks, SwaggerUI works again and the Bearer Security feature also works nicely. – yenta Jan 28 '19 at 09:37
-
@mythz How to configure swagger UI to use bearer token authentication in V5.0? – user3603110 Jul 02 '20 at 07:08