From 087e7d63af5b0cd0c526b8f1639da01ce7991d18 Mon Sep 17 00:00:00 2001 From: meysam Date: Tue, 5 Mar 2024 11:45:38 +0400 Subject: [PATCH 1/6] Update target framework and remove unnecessary dependencies The target framework of the 'AuthorizationServer' project has been updated from 'netcoreapp2.0' to 'net8.0'. As a part of this update, several unnecessary package references have been removed and the 'Authlete.Authlete' package has been upgraded to version '1.5.0'. Additionally, 'ImplicitUsings' and 'Nullable' were also enabled. --- AuthorizationServer/AuthorizationServer.csproj | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/AuthorizationServer/AuthorizationServer.csproj b/AuthorizationServer/AuthorizationServer.csproj index f26a38e..f46c213 100644 --- a/AuthorizationServer/AuthorizationServer.csproj +++ b/AuthorizationServer/AuthorizationServer.csproj @@ -1,7 +1,9 @@ - netcoreapp2.0 + net8.0 + enable + enable 1.0 @@ -17,13 +19,7 @@ - - - - - - - + From 89cb50cda8a10be31e554d3189ee0c74fed7ad39 Mon Sep 17 00:00:00 2001 From: meysam Date: Mon, 11 Mar 2024 11:46:44 +0400 Subject: [PATCH 2/6] Update server configurations and routing in Startup.cs The commit introduces Microsoft.Extensions.Hosting library into the AuthorizationServer's Startup.cs. It also replaces services.AddMvc().AddWebApiConventions() with services.AddControllers() and modifies the Configure method to accommodate these changes. Lastly, it updates the application's routing to use app.UseRouting() and configures endpoints specifically for controllers. --- AuthorizationServer/Startup.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/AuthorizationServer/Startup.cs b/AuthorizationServer/Startup.cs index 22ba409..3d70917 100644 --- a/AuthorizationServer/Startup.cs +++ b/AuthorizationServer/Startup.cs @@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Authlete.Api; using Authlete.Conf; @@ -42,7 +43,7 @@ public void ConfigureServices(IServiceCollection services) // AddWebApiConventions() is added by WebApiCompatShim. // Calling the method enables Web API implementations // to return an HttpResponseMessage instance directly. - services.AddMvc().AddWebApiConventions(); + services.AddControllers(); // Register an instance of IAuthleteApi so controllers // can refer to it in order to call Authlete Web APIs. @@ -57,7 +58,7 @@ public void ConfigureServices(IServiceCollection services) } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { @@ -66,7 +67,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseDefaultFiles(); app.UseStaticFiles(); - app.UseMvc(); + + // Updated to use routing + app.UseRouting(); + + // Configure endpoints for controllers + app.UseEndpoints(endpoints => + { + // Ensure this matches your app's routing needs + endpoints.MapControllers(); + }); } From aef56737c83189a5d4d706cb45399c399cf3393c Mon Sep 17 00:00:00 2001 From: meysam Date: Mon, 11 Mar 2024 15:26:51 +0400 Subject: [PATCH 3/6] Add Swagger for API Documentation and Update BaseController Access Levels This commit introduces Swagger to enhance the API documentation and testing capabilities of the project. It also configures the generation of an XML comment file, offering detailed insights into the API endpoints. The Swagger UI is now accessible from the application's root URL. Additionally, access levels for certain methods within the BaseController class have been changed from public to protected to improve encapsulation. This adjustment ensures better method management in Swagger, allowing protected methods to be handled appropriately without requiring REST attributes. --- .../AuthorizationServer.csproj | 6 +++++ .../Controllers/BaseController.cs | 6 ++--- AuthorizationServer/Startup.cs | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/AuthorizationServer/AuthorizationServer.csproj b/AuthorizationServer/AuthorizationServer.csproj index f46c213..01a7a17 100644 --- a/AuthorizationServer/AuthorizationServer.csproj +++ b/AuthorizationServer/AuthorizationServer.csproj @@ -20,6 +20,12 @@ + + + true + $(NoWarn);1591 + + diff --git a/AuthorizationServer/Controllers/BaseController.cs b/AuthorizationServer/Controllers/BaseController.cs index 1244330..e8e6fdc 100644 --- a/AuthorizationServer/Controllers/BaseController.cs +++ b/AuthorizationServer/Controllers/BaseController.cs @@ -51,8 +51,8 @@ public BaseController(IAuthleteApi api) /// /// Read the request body as a string. - /// - public async Task ReadRequestBodyAsString() + /// ı + protected async Task ReadRequestBodyAsString() { using (var reader = new StreamReader(Request.Body, Encoding.UTF8)) { @@ -72,7 +72,7 @@ public async Task ReadRequestBodyAsString() /// /// The name of an HTTP header. /// - public string GetRequestHeaderValue(string headerName) + protected string GetRequestHeaderValue(string headerName) { StringValues values = Request.Headers[headerName]; diff --git a/AuthorizationServer/Startup.cs b/AuthorizationServer/Startup.cs index 3d70917..a16d453 100644 --- a/AuthorizationServer/Startup.cs +++ b/AuthorizationServer/Startup.cs @@ -21,6 +21,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.OpenApi.Models; +using System.Reflection; using Authlete.Api; using Authlete.Conf; @@ -44,6 +46,17 @@ public void ConfigureServices(IServiceCollection services) // Calling the method enables Web API implementations // to return an HttpResponseMessage instance directly. services.AddControllers(); + + // Register the Swagger generator + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Authlete Authorization Server", Version = "v1" }); + + // Optional: Set the comments path for the Swagger JSON and UI. + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath); + }); // Register an instance of IAuthleteApi so controllers // can refer to it in order to call Authlete Web APIs. @@ -64,6 +77,16 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseDeveloperExceptionPage(); } + + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(); + + // Enable middleware to serve swagger-ui assets (HTML, JS, CSS, etc.) + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "Authlete Authorization Server API"); + c.RoutePrefix = string.Empty; // To serve the Swagger UI at the app's root + }); app.UseDefaultFiles(); app.UseStaticFiles(); From 56efb33d2618f8cf84a84661ee4795f6a45746ce Mon Sep 17 00:00:00 2001 From: meysam Date: Mon, 11 Mar 2024 16:29:41 +0400 Subject: [PATCH 4/6] Add base path in startup configuration --- AuthorizationServer/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AuthorizationServer/Startup.cs b/AuthorizationServer/Startup.cs index a16d453..cd0d38b 100644 --- a/AuthorizationServer/Startup.cs +++ b/AuthorizationServer/Startup.cs @@ -80,6 +80,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); + app.UsePathBase("/"); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS, etc.) app.UseSwaggerUI(c => From 84eef276580a0aafb19955c02135750752bac50c Mon Sep 17 00:00:00 2001 From: meysam Date: Tue, 12 Mar 2024 23:29:42 +0400 Subject: [PATCH 5/6] The outdated comment in `Startup.cs` that referred to the `AddWebApiConventions` method, previously added by `WebApiCompatShim`, has been removed. --- AuthorizationServer/Startup.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AuthorizationServer/Startup.cs b/AuthorizationServer/Startup.cs index cd0d38b..862be2d 100644 --- a/AuthorizationServer/Startup.cs +++ b/AuthorizationServer/Startup.cs @@ -42,7 +42,6 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { - // AddWebApiConventions() is added by WebApiCompatShim. // Calling the method enables Web API implementations // to return an HttpResponseMessage instance directly. services.AddControllers(); From 8633a6a3c46451ec55718178b5c458d46fdc1ee9 Mon Sep 17 00:00:00 2001 From: meysam Date: Tue, 12 Mar 2024 23:39:10 +0400 Subject: [PATCH 6/6] Updates the comment for the ConfigureServices method in the Startup.cs. --- AuthorizationServer/Startup.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AuthorizationServer/Startup.cs b/AuthorizationServer/Startup.cs index 862be2d..853e485 100644 --- a/AuthorizationServer/Startup.cs +++ b/AuthorizationServer/Startup.cs @@ -42,8 +42,10 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { - // Calling the method enables Web API implementations - // to return an HttpResponseMessage instance directly. + // AddControllers() method registers the services + // of Controller type to the service collection, + // which will be used to serve MVC-style controller + // endpoints in the application. services.AddControllers(); // Register the Swagger generator