Open itsoli91 opened 2 years ago
Hi @itsoli91 ,
I'm using NSwag 13.18.2 here, and my Startup.cs
looks something like this:
services.AddOpenApiDocument((configure, provider) =>
{
configure.Title = "My Amazing API";
configure.Description = "This API is amazing.";
configure.DocumentName = $"v1.0";
configure.Version = "1.0.0";
configure.UseControllerSummaryAsTagDescription = true;
configure.AddSecurity("Bearer", Array.Empty<string>(), new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.OAuth2,
Description = "The Identity Server will return an access token; this should be added to every request, using the Authorization header with the Bearer scheme.",
Flows = new OpenApiOAuthFlows
{
ClientCredentials = new OpenApiOAuthFlow
{
Scopes = new Dictionary<string, string>{
{ "read", "The user is able to read from the resource" },
{ "write", "The user is able to write to the resource" },
{ "delete", "The user is able to delete the resource" }
},
TokenUrl = $"{IdentityServerUrl}/connect/token"
}
}
});
As the code hopefully makes clear, this implements the OAuth client credentials profile (for services talking directly to the API ,using a Client ID and a Client Secret. NSwag supports other OAuth profiles, just change the property that is being set on the OpenApiOAuthFlows
instance.
I was trying to migrate SwashBuckle to NSwag but I am having same issues with AddSecurityRequirement, AddSecurityDefinition and DocInclusionPredicate of SwashBuckle.
Hi, Currently we are using this code to add Security Definition, however I can't find AddSecurityRequirement in nswag? Any help on rewriting this price of code with nswag version ?