diff --git a/IdentityServer.Api/IdentityServer.Api.csproj b/IdentityServer.Api/IdentityServer.Api.csproj index c893d3e..be89171 100644 --- a/IdentityServer.Api/IdentityServer.Api.csproj +++ b/IdentityServer.Api/IdentityServer.Api.csproj @@ -10,6 +10,7 @@ + diff --git a/IdentityServer.Api/Startup.cs b/IdentityServer.Api/Startup.cs index c0d1f03..3063214 100644 --- a/IdentityServer.Api/Startup.cs +++ b/IdentityServer.Api/Startup.cs @@ -1,5 +1,4 @@ using AutoMapper; -using IdentityServer.Api.Swagger; using IdentityServer.Application; using IdentityServer.Domain.Data; using MediatR; @@ -9,6 +8,8 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using NDB.Extensions.Swagger; +using NDB.Extensions.Swagger.Constants; using Newtonsoft.Json; using System.Reflection; @@ -39,7 +40,7 @@ namespace IdentityServer.Api typeof(Application.Mappings.MappingProfile).Assembly); // Swagger - services.AddSwagger(); + services.AddSwagger("Identity Server API", AuthorizationType.None); // Data access services.AddDataAccess(); @@ -74,7 +75,7 @@ namespace IdentityServer.Api { endpoints.MapControllers(); }); - app.ConfigureSwagger(); + app.ConfigureSwagger("IdentityServer API"); } } } diff --git a/IdentityServer.Api/Swagger/DtoSchemaFilter.cs b/IdentityServer.Api/Swagger/DtoSchemaFilter.cs deleted file mode 100644 index 6dbf302..0000000 --- a/IdentityServer.Api/Swagger/DtoSchemaFilter.cs +++ /dev/null @@ -1,36 +0,0 @@ -using IdentityServer.Application.Commands; -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; -using System.Linq; - -namespace IdentityServer.Api.Swagger -{ - public class DtoSchemaFilter : ISchemaFilter - { - public void Apply(OpenApiSchema schema, SchemaFilterContext context) - { - var targetType = context.Type; - while (targetType != null) - { - if (typeof(ICommand).IsAssignableFrom(targetType)) - { - foreach (var property in schema.Properties.ToList()) - { - property.Value.ReadOnly = false; - - switch (property.Key) - { - case "metadata": - schema.Properties.Remove(property.Key); - break; - default: - break; - } - } - } - - targetType = targetType.DeclaringType; - } - } - } -} diff --git a/IdentityServer.Api/Swagger/PathParamsOperationFilter.cs b/IdentityServer.Api/Swagger/PathParamsOperationFilter.cs deleted file mode 100644 index 21bdeca..0000000 --- a/IdentityServer.Api/Swagger/PathParamsOperationFilter.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; -using System; -using System.Linq; -using System.Text.RegularExpressions; - -namespace IdentityServer.Api.Swagger -{ - public class PathParamsOperationFilter : IOperationFilter - { - public void Apply(OpenApiOperation operation, OperationFilterContext context) - { - const string paramCaptureGroup = "param"; - - foreach (var parameter in operation.Parameters.ToList()) - { - if (parameter.Name.ToLowerInvariant().StartsWith("metadata")) - { - operation.Parameters.Remove(parameter); - } - } - - var openApiPathParameters = operation.Parameters.Where(param => param.In == ParameterLocation.Path).ToList(); - var pathParamRegEx = $@"\{{(?<{paramCaptureGroup}>[^\}}]+)\}}"; - - if (openApiPathParameters.Any()) - { - var pathParameterMatches = Regex.Matches(context.ApiDescription.RelativePath, pathParamRegEx, RegexOptions.Compiled); - var pathParameters = pathParameterMatches.Select(x => x.Groups[paramCaptureGroup].Value); - - foreach (var openApiPathParameter in openApiPathParameters) - { - var correspondingPathParameter = pathParameters.FirstOrDefault(x => - string.Equals(x, openApiPathParameter.Name, StringComparison.InvariantCultureIgnoreCase)); - - if (correspondingPathParameter != null) - openApiPathParameter.Name = correspondingPathParameter; - } - } - } - } -} diff --git a/IdentityServer.Api/Swagger/SwaggerExtensions.cs b/IdentityServer.Api/Swagger/SwaggerExtensions.cs deleted file mode 100644 index 660cfbb..0000000 --- a/IdentityServer.Api/Swagger/SwaggerExtensions.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; -using System.Collections.Generic; -using System.Linq; - -namespace IdentityServer.Api.Swagger -{ - public static class SwaggerExtensions - { - public static IServiceCollection AddSwagger(this IServiceCollection services) - { - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", - new OpenApiInfo - { - Title = "Identity Server API", - Version = "v1" - }); - - c.OperationFilter(); - c.SchemaFilter(); - c.CustomSchemaIds(type => type.ToString()); - }); - - return services; - } - - public static IApplicationBuilder ConfigureSwagger(this IApplicationBuilder applicationBuilder) - { - applicationBuilder.UseSwagger(c => - { - c.PreSerializeFilters.Add((swagger, httpRequest) => - { - var (host, basePath, scheme) = GetUrlComponents(httpRequest); - - swagger.Servers = new List - { - new OpenApiServer {Url = $"{scheme}://{host}{basePath}"} - }; - }); - c.RouteTemplate = "swagger/{documentName}/swagger.json"; - }); - - applicationBuilder.UseSwaggerUI(c => - { - c.SwaggerEndpoint("v1/swagger.json", "IdentityServer API"); - c.RoutePrefix = $"swagger"; - }); - - return applicationBuilder; - } - - private static (string host, string basePath, string scheme) GetUrlComponents(HttpRequest request) - { - var host = ExtractHost(request); - var basePath = ExtractBasePath(request); - var scheme = ExtractScheme(request); - - return (host, basePath, scheme); - } - - private static string ExtractHost(HttpRequest request) - { - if (request.Headers.ContainsKey("X-Forwarded-Host")) - return request.Headers["X-Forwarded-Host"].First(); - - return request.Host.Value; - } - - private static string ExtractBasePath(HttpRequest request) - { - if (request.Headers.ContainsKey("X-Forwarded-PathBase")) - return request.Headers["X-Forwarded-PathBase"].First(); - - return string.Empty; - } - - private static string ExtractScheme(HttpRequest request) - { - return request.Headers["X-Forwarded-Proto"].FirstOrDefault() ?? request.Scheme; - } - } -} diff --git a/IdentityServer.Application/Commands/AuthenticateUser.cs b/IdentityServer.Application/Commands/AuthenticateUser.cs index 4c744a4..1cfd19c 100644 --- a/IdentityServer.Application/Commands/AuthenticateUser.cs +++ b/IdentityServer.Application/Commands/AuthenticateUser.cs @@ -1,4 +1,5 @@ using IdentityServer.PublishedLanguage.Dto; +using NDB.Application.DataContracts; namespace IdentityServer.Application.Commands { diff --git a/IdentityServer.Application/Commands/AuthorizeToken.cs b/IdentityServer.Application/Commands/AuthorizeToken.cs index 280d889..a00e823 100644 --- a/IdentityServer.Application/Commands/AuthorizeToken.cs +++ b/IdentityServer.Application/Commands/AuthorizeToken.cs @@ -1,4 +1,5 @@ using IdentityServer.PublishedLanguage.Dto; +using NDB.Application.DataContracts; namespace IdentityServer.Application.Commands { diff --git a/IdentityServer.Application/Commands/Command.cs b/IdentityServer.Application/Commands/Command.cs deleted file mode 100644 index dc28127..0000000 --- a/IdentityServer.Application/Commands/Command.cs +++ /dev/null @@ -1,45 +0,0 @@ -using MediatR; -using System; -using System.Collections.Generic; - -namespace IdentityServer.Application.Commands -{ - public abstract class Command : ICommand, IRequest - { - public Metadata Metadata { get; } - - protected Command() - { - Metadata = new Metadata() { CorrelationId = Guid.NewGuid() }; - } - - protected Command(Metadata metadata) - { - Metadata = metadata; - } - } - - public interface ICommand - { - } - - public class Metadata : Dictionary - { - public const string CorrelationIdKey = "CorrelationId"; - - public Guid CorrelationId - { - get - { - return Guid.Parse(this[CorrelationIdKey]); - } - set - { - if (ContainsKey(CorrelationIdKey)) - this[CorrelationIdKey] = value.ToString(); - else - Add(CorrelationIdKey, value.ToString()); - } - } - } -} diff --git a/IdentityServer.Application/IdentityServer.Application.csproj b/IdentityServer.Application/IdentityServer.Application.csproj index 7fd2280..51020cf 100644 --- a/IdentityServer.Application/IdentityServer.Application.csproj +++ b/IdentityServer.Application/IdentityServer.Application.csproj @@ -11,6 +11,7 @@ + diff --git a/IdentityServer.Application/Queries/Query.cs b/IdentityServer.Application/Queries/Query.cs deleted file mode 100644 index 476452a..0000000 --- a/IdentityServer.Application/Queries/Query.cs +++ /dev/null @@ -1,6 +0,0 @@ -using MediatR; - -namespace IdentityServer.Application.Queries -{ - public abstract class Query : IRequest, IBaseRequest { } -} diff --git a/IdentityServer.sln b/IdentityServer.sln index 80abf51..bdd94ce 100644 --- a/IdentityServer.sln +++ b/IdentityServer.sln @@ -12,16 +12,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution dependencies.props = dependencies.props Directory.Build.props = Directory.Build.props Notes.txt = Notes.txt + NuGet.config = NuGet.config ReleaseNotes.xml = ReleaseNotes.xml EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer.Application", "IdentityServer.Application\IdentityServer.Application.csproj", "{6556D255-AF22-478E-A71A-BE37C16D5EE4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Application", "IdentityServer.Application\IdentityServer.Application.csproj", "{6556D255-AF22-478E-A71A-BE37C16D5EE4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer.Domain", "IdentityServer.Domain\IdentityServer.Domain.csproj", "{5890B079-3CB0-4AD6-8809-BB2E081590B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Domain", "IdentityServer.Domain\IdentityServer.Domain.csproj", "{5890B079-3CB0-4AD6-8809-BB2E081590B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer.Domain.Data", "IdentityServer.Domain.Data\IdentityServer.Domain.Data.csproj", "{CE81A435-49AC-4544-A381-FAC91BEB3C49}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Domain.Data", "IdentityServer.Domain.Data\IdentityServer.Domain.Data.csproj", "{CE81A435-49AC-4544-A381-FAC91BEB3C49}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer.PublishedLanguage", "IdentityServer.PublishedLanguage\IdentityServer.PublishedLanguage.csproj", "{67B4D1FF-D02E-4DA6-9FB8-F71667360448}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.PublishedLanguage", "IdentityServer.PublishedLanguage\IdentityServer.PublishedLanguage.csproj", "{67B4D1FF-D02E-4DA6-9FB8-F71667360448}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000..fdd86c4 --- /dev/null +++ b/NuGet.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dependencies.props b/dependencies.props index b606756..6726903 100644 --- a/dependencies.props +++ b/dependencies.props @@ -10,5 +10,7 @@ 6.0.0 5.3.1 3.1.3 + 1.0.0 + 1.0.0 \ No newline at end of file