From 685be06f8036e9f525eda207bdaa14e5e17d5311 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 26 Jun 2021 21:55:04 +0300 Subject: [PATCH] NDB.Extensions.Swagger updates --- .../Constants/AuthorizationType.cs | 3 +- .../NDB.Extensions.Swagger.csproj | 2 +- NDB.Extensions.Swagger/SwaggerExtensions.cs | 60 +++++++++++-------- Notes.txt | 2 +- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/NDB.Extensions.Swagger/Constants/AuthorizationType.cs b/NDB.Extensions.Swagger/Constants/AuthorizationType.cs index 3abf26f..a0c64cb 100644 --- a/NDB.Extensions.Swagger/Constants/AuthorizationType.cs +++ b/NDB.Extensions.Swagger/Constants/AuthorizationType.cs @@ -3,6 +3,7 @@ public enum AuthorizationType { None, - Basic + Basic, + InhouseIdentity } } diff --git a/NDB.Extensions.Swagger/NDB.Extensions.Swagger.csproj b/NDB.Extensions.Swagger/NDB.Extensions.Swagger.csproj index 46ef9fb..aae4c04 100644 --- a/NDB.Extensions.Swagger/NDB.Extensions.Swagger.csproj +++ b/NDB.Extensions.Swagger/NDB.Extensions.Swagger.csproj @@ -8,7 +8,7 @@ https://dev.azure.com/tstanciu94/NDB Git NDB swagger - 1.0.1 + 1.0.2 diff --git a/NDB.Extensions.Swagger/SwaggerExtensions.cs b/NDB.Extensions.Swagger/SwaggerExtensions.cs index 3b35ded..6c3e8fa 100644 --- a/NDB.Extensions.Swagger/SwaggerExtensions.cs +++ b/NDB.Extensions.Swagger/SwaggerExtensions.cs @@ -51,33 +51,11 @@ namespace NDB.Extensions.Swagger return; case AuthorizationType.Basic: - options.AddSecurityDefinition("Basic", - new OpenApiSecurityScheme - { - 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'", - Name = "Authorization", - Scheme = "Basic", - Type = SecuritySchemeType.ApiKey - }); + options.SetAuthorization(authorizationType.ToString(), "Basic"); + break; - options.AddSecurityRequirement(new OpenApiSecurityRequirement() - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "Basic" - }, - Scheme = "Basic", - Name = "Authorization", - In = ParameterLocation.Header - }, - new List() - } - }); + case AuthorizationType.InhouseIdentity: + options.SetAuthorization(authorizationType.ToString(), "Identity"); break; default: @@ -85,6 +63,36 @@ namespace NDB.Extensions.Swagger } } + private static void SetAuthorization(this SwaggerGenOptions options, string schemeName, string schemeKey) + { + options.AddSecurityDefinition(schemeName, new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + 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", + Scheme = schemeName, + Type = SecuritySchemeType.ApiKey + }); + + options.AddSecurityRequirement(new OpenApiSecurityRequirement() + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = schemeName + }, + Scheme = schemeName, + Name = "Authorization", + In = ParameterLocation.Header + }, + new List() + } + }); + } + public static IApplicationBuilder ConfigureSwagger(this IApplicationBuilder applicationBuilder, string endpointName) { applicationBuilder.UseSwagger(c => diff --git a/Notes.txt b/Notes.txt index 4529395..3135542 100644 --- a/Notes.txt +++ b/Notes.txt @@ -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.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