From 7a562bea6299a9c7ee6c3f62540a67e84f29a403 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 1 Jul 2025 14:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGSS.sln | 25 +++++++++++ AGSS/AGSS.csproj | 22 +++++++++ AGSS/AGSS.http | 6 +++ AGSS/Program.cs | 69 +++++++++++++++++++++++++++++ AGSS/Properties/launchSettings.json | 41 +++++++++++++++++ AGSS/appsettings.Development.json | 8 ++++ AGSS/appsettings.json | 14 ++++++ 7 files changed, 185 insertions(+) create mode 100644 AGSS.sln create mode 100644 AGSS/AGSS.csproj create mode 100644 AGSS/AGSS.http create mode 100644 AGSS/Program.cs create mode 100644 AGSS/Properties/launchSettings.json create mode 100644 AGSS/appsettings.Development.json create mode 100644 AGSS/appsettings.json diff --git a/AGSS.sln b/AGSS.sln new file mode 100644 index 0000000..089e450 --- /dev/null +++ b/AGSS.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AGSS", "AGSS\AGSS.csproj", "{BE8E1B7F-9100-4C7B-8BB5-378DEFE383ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE8E1B7F-9100-4C7B-8BB5-378DEFE383ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE8E1B7F-9100-4C7B-8BB5-378DEFE383ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE8E1B7F-9100-4C7B-8BB5-378DEFE383ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE8E1B7F-9100-4C7B-8BB5-378DEFE383ED}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DE38D7BB-609D-49CF-9C95-1E7BC23DD8D9} + EndGlobalSection +EndGlobal diff --git a/AGSS/AGSS.csproj b/AGSS/AGSS.csproj new file mode 100644 index 0000000..a799f8c --- /dev/null +++ b/AGSS/AGSS.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/AGSS/AGSS.http b/AGSS/AGSS.http new file mode 100644 index 0000000..7b67830 --- /dev/null +++ b/AGSS/AGSS.http @@ -0,0 +1,6 @@ +@AGSS_HostAddress = http://localhost:5200 + +GET {{AGSS_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/AGSS/Program.cs b/AGSS/Program.cs new file mode 100644 index 0000000..1b71f31 --- /dev/null +++ b/AGSS/Program.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; + + + + + + + + + + + +var builder = WebApplication.CreateBuilder(args); + + + + +// ¶ÁÈ¡ÅäÖà +var domain = builder.Configuration["Auth0:Domain"]; +var audience =builder.Configuration["Auth0:Audience"]; + + +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.Authority = domain; + options.Audience = audience; + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidIssuer = domain, + ValidAudience = audience + }; + }); +builder.Services.AddAuthorization(); + + + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthentication(); + +app.UseAuthorization(); + +#pragma warning disable ASP0014 // Suggest using top level route registrations +app.UseEndpoints(endpoints => endpoints.MapControllers()); +#pragma warning restore ASP0014 // Suggest using top level route registrations + + +app.MapControllers(); + +app.Run(); diff --git a/AGSS/Properties/launchSettings.json b/AGSS/Properties/launchSettings.json new file mode 100644 index 0000000..26eb3f2 --- /dev/null +++ b/AGSS/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26445", + "sslPort": 44339 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5200", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7183;http://localhost:5200", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/AGSS/appsettings.Development.json b/AGSS/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/AGSS/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/AGSS/appsettings.json b/AGSS/appsettings.json new file mode 100644 index 0000000..ec10538 --- /dev/null +++ b/AGSS/appsettings.json @@ -0,0 +1,14 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "Auth0": { + "Domain": "", + "Audience": "", + "ClientId": "" + } +}