I'm trying to figure out how I can configure SwaggerGen to populate/display the fields/parameters for OpenIddict and client credentials grant.
services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
options.UseOpenIddict();
});
services.AddOpenIddict()
.AddCore(options =>
{
// Configure OpenIddict to use the Entity Framework Core stores and models.
// Note: call ReplaceDefaultEntities() to replace the default entities.
options.UseEntityFrameworkCore().UseDbContext<AppDbContext>();
})
.AddServer(options =>
{
// Enable the token endpoint.
options.SetTokenEndpointUris("/connect/token");
// Enable the client credentials flow.
options.AllowClientCredentialsFlow();
// Register the signing and encryption credentials.
options.AddDevelopmentEncryptionCertificate()
.AddDevelopmentSigningCertificate();
// Register the ASP.NET Core host and configure the ASP.NET Core options.
options.UseAspNetCore()
.EnableTokenEndpointPassthrough();
})
.AddValidation(options =>
{
// Import the configuration from the local OpenIddict server instance.
options.UseLocalServer();
// Register the ASP.NET Core host.
options.UseAspNetCore();
});
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "PCM", Version = "v1" });
options.AddSecurityDefinition("Authentication", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OpenIdConnect,
Description = "Description",
In = ParameterLocation.Header,
Name = "Notsure",
Flows = new OpenApiOAuthFlows
{
ClientCredentials = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("/connect/token", UriKind.Relative),
TokenUrl = new Uri("/connect/token", UriKind.Relative),
Scopes = new Dictionary<string, string>()
{
}
}
},
OpenIdConnectUrl = new Uri("/connect/authorize", UriKind.Relative)
});
});
It's displaying the Authorize button but when I click it, it opens an empty modal like shown in the below image:
Appreciate anyone who can point me at some docs that would explain what I need to configure in services.AddSwaggerGen()
to get this configured so we can easily test our API through the interactive documentation generated by Swagger.
Implicit = new OpenApiOAuthFlow
seems wrong. You're trying to use client credentials flow, not implicit. – Attachment