Swashbuckle.AspNetCore: Available Authorizations modal is empty with v5 OpenIdConnect configuration
Running .Net Core 2.2 and Swashbuckle.AspNetCore 5.0.0-rc2.
Trying to setup OIDC configuration, but the Available Authorizations modal is blank, so cannot proceed with authentication.
Configuration as follows:
services.AddSwaggerGen(c => {
...
c.AddSecurityDefinition("token", new OpenApiSecurityScheme {
Type = SecuritySchemeType.OpenIdConnect,
OpenIdConnectUrl = new Uri($"https://login.microsoftonline.com/{tenant}/v2.0/.well-known-openid-configuration")
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
{
new OpenApiSecurityScheme {
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "token"
}, new string[] { }
}
});
...
});
services.UseSwaggerUI(c => {
...
c.OAuthClientId(_clientId);
...
});
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 22
- Comments: 27 (3 by maintainers)
I met the same issue before and resolved it.
Now the available Authorization header works fine.
Please check my latest sample using SwashBuckle v5.5.1 and netcore 3.1 https://github.com/capcom923/MySwashBuckleSwaggerWithJwtToken
Is there an example I can follow on how to configure Swashbuckle to use OIDC?
OpenID Connect Discovery is now supported in Swagger UI v. 3.38.0.
Any update on this?
@cjamesrohan I’ve managed to populate the Available Authorization pop up with the required action items. My
Startup.cs
file looks as follows:ConfigureServices method
where
AssignOAuth2SecurityRequirements
Operation filter class is:Note:
Reference
object insideOpenApiSecurityRequirement
of the[Authorize]
d operation should have reference to theName
of the same SecurityScheme you define insideservices.AddSwaggerGen.AddSecurityDefinition
(i.e. your global SecurityDefinition)(as shown above)I hope this helps.
I had a similar issue where “Available authorizations” was appearing empty when using
openIdConnect
. After some frustrating debugging, I discovered it was a CORS issue. My auth server is on a different domain so when swagger-ui attempts to fetch the/.well-known/openid-configuration
it is blocked by the CORS policy. Try loading swagger-ui with the developer console open and check for errors. Firefox seems better at reporting CORS issues than Chrome.From the Swagger docs
And here’s the related issue in the swagger-ui repo: https://github.com/swagger-api/swagger-ui/issues/3517
It looks like OpenIDConnect is not supported in the Swagger UI that Swashbuckle takes a dependency on: https://github.com/swagger-api/swagger-ui/issues/3517
And it does not look like it’s on the roadmap either: https://github.com/swagger-api/swagger-ui/issues/5473
@capcom923 We are hoping to get it to work with
SecuritySchemeType.OpenIdConnect
which your sample doesn’t resolve at all.We have the same issue.
We are running .net core 3.0.0 with Swashbuckle.AspNetCore 5.0.0-rc4 The issue only seems to affect the type
SecuritySchemeType.OpenIdConnect
.@Alex-Torres This isn’t a working sample, but maybe somebody could point out if there is an issue with the following securityScheme, and then from there use that as a working example? It seems like the problem is with SwaggerUI , rather than Swashbuckle
The openApi.json file is being generated by the
Swashbuckle.AspNetCore
package, but the SwaggerUI project is running using the 3.43.0 docker image, in an attempt to isolate the SwaggerUI project with the latest OpenId connect supportEdit I tried adding the
security
section as below, but the modal is still emptyI also have an open ticket somewhere for swagger-ui. Thanks for your response @domaindrivendev! Whenever this gets implemented by them, is there a plan to finish implementation in Swashbuckle? Just curious.