NDB.Extensions.Swagger updates

messaging
Tudor Stanciu 2021-06-26 21:55:04 +03:00
parent e842f56caf
commit 685be06f80
4 changed files with 38 additions and 29 deletions

View File

@ -3,6 +3,7 @@
public enum AuthorizationType public enum AuthorizationType
{ {
None, None,
Basic Basic,
InhouseIdentity
} }
} }

View File

@ -8,7 +8,7 @@
<RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl> <RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageTags>NDB swagger</PackageTags> <PackageTags>NDB swagger</PackageTags>
<Version>1.0.1</Version> <Version>1.0.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -51,13 +51,26 @@ namespace NDB.Extensions.Swagger
return; return;
case AuthorizationType.Basic: case AuthorizationType.Basic:
options.AddSecurityDefinition("Basic", options.SetAuthorization(authorizationType.ToString(), "Basic");
new OpenApiSecurityScheme break;
case AuthorizationType.InhouseIdentity:
options.SetAuthorization(authorizationType.ToString(), "Identity");
break;
default:
throw new NotImplementedException($"Swagger extensions: Authorization type '{authorizationType}' is not implemented.");
}
}
private static void SetAuthorization(this SwaggerGenOptions options, string schemeName, string schemeKey)
{
options.AddSecurityDefinition(schemeName, new OpenApiSecurityScheme
{ {
In = ParameterLocation.Header, In = ParameterLocation.Header,
Description = @"JWT Authorization header using the Basic scheme. Enter 'Basic' [space] and then your token in the text input below. Example: 'Basic 12345abcdef'", Description = $@"JWT Authorization header using the {schemeName} scheme. Enter '{schemeKey}' [space] and then your token in the text input below. Example: '{schemeKey} 12345abcdef'",
Name = "Authorization", Name = "Authorization",
Scheme = "Basic", Scheme = schemeName,
Type = SecuritySchemeType.ApiKey Type = SecuritySchemeType.ApiKey
}); });
@ -69,20 +82,15 @@ namespace NDB.Extensions.Swagger
Reference = new OpenApiReference Reference = new OpenApiReference
{ {
Type = ReferenceType.SecurityScheme, Type = ReferenceType.SecurityScheme,
Id = "Basic" Id = schemeName
}, },
Scheme = "Basic", Scheme = schemeName,
Name = "Authorization", Name = "Authorization",
In = ParameterLocation.Header In = ParameterLocation.Header
}, },
new List<string>() new List<string>()
} }
}); });
break;
default:
throw new NotImplementedException($"Swagger extensions: Authorization type '{authorizationType}' is not implemented.");
}
} }
public static IApplicationBuilder ConfigureSwagger(this IApplicationBuilder applicationBuilder, string endpointName) public static IApplicationBuilder ConfigureSwagger(this IApplicationBuilder applicationBuilder, string endpointName)

View File

@ -18,7 +18,7 @@ Push packages:
dotnet nuget push NDB.Application.DataContracts.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Application.DataContracts.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget
dotnet nuget push NDB.Extensions.Swagger.1.0.1.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Swagger.1.0.2.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget
dotnet nuget push NDB.Extensions.Http.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Http.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget