From d94e2a0ad8955020e96f86d34abd29cbd10fda8f Mon Sep 17 00:00:00 2001 From: savorboard Date: Sat, 11 Nov 2023 11:53:26 +0800 Subject: [PATCH] Update samples --- .../Properties/launchSettings.json | 28 ++++++++ .../Sample.Dashboard.Auth.csproj | 4 +- samples/Sample.Dashboard.Auth/Startup.cs | 71 ++++++++----------- 3 files changed, 60 insertions(+), 43 deletions(-) create mode 100644 samples/Sample.Dashboard.Auth/Properties/launchSettings.json diff --git a/samples/Sample.Dashboard.Auth/Properties/launchSettings.json b/samples/Sample.Dashboard.Auth/Properties/launchSettings.json new file mode 100644 index 000000000..240d046c2 --- /dev/null +++ b/samples/Sample.Dashboard.Auth/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49319/", + "sslPort": 44328 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "cap", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Sample.Dashboard.Auth": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001" + } + } +} \ No newline at end of file diff --git a/samples/Sample.Dashboard.Auth/Sample.Dashboard.Auth.csproj b/samples/Sample.Dashboard.Auth/Sample.Dashboard.Auth.csproj index 436e6da9b..e19f43294 100644 --- a/samples/Sample.Dashboard.Auth/Sample.Dashboard.Auth.csproj +++ b/samples/Sample.Dashboard.Auth/Sample.Dashboard.Auth.csproj @@ -6,12 +6,12 @@ - - + + diff --git a/samples/Sample.Dashboard.Auth/Startup.cs b/samples/Sample.Dashboard.Auth/Startup.cs index c44242f33..49d43d420 100644 --- a/samples/Sample.Dashboard.Auth/Startup.cs +++ b/samples/Sample.Dashboard.Auth/Startup.cs @@ -1,53 +1,47 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Savorboard.CAP.InMemoryMessageQueue; namespace Sample.Dashboard.Auth { public class Startup { - private readonly IConfiguration _configuration; - - public Startup(IConfiguration configuration) - { - _configuration = configuration; - } - public void ConfigureServices(IServiceCollection services) { - services - .AddAuthorization((options => - { - // only if you want to apply role filter to CAP Dashboard user - options.AddPolicy("PolicyCap", policy => policy.RequireRole("admin.events")); - })) - .AddAuthentication(options => - { - options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; - }) - .AddCookie() - .AddOpenIdConnect(options => - { - options.Authority = "https://demo.duendesoftware.com/"; - options.ClientId = "interactive.confidential"; - options.ClientSecret = "secret"; - options.ResponseType = "code"; - options.UsePkce = true; + services + .AddAuthorization((options => + { + // only if you want to apply role filter to CAP Dashboard user + options.AddPolicy("PolicyCap", policy => policy.RequireRole("admin.events")); + })) + .AddAuthentication(options => + { + options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; + }) + .AddCookie() + .AddOpenIdConnect(options => + { + options.RequireHttpsMetadata = false; + options.Authority = "https://demo.duendesoftware.com/"; + options.ClientId = "interactive.confidential"; + options.ClientSecret = "secret"; + options.ResponseType = "code"; + options.UsePkce = true; - options.Scope.Clear(); - options.Scope.Add("openid"); - options.Scope.Add("profile"); - }) - .AddScheme("MyDashboardScheme",null); + options.Scope.Clear(); + options.Scope.Add("openid"); + options.Scope.Add("profile"); + }); + //.AddScheme("MyDashboardScheme",null); services.AddCors(x => { x.AddDefaultPolicy(p => { - p.WithOrigins("http://localhost:8080").AllowCredentials().AllowAnyHeader().AllowAnyMethod(); + p.WithOrigins("https://localhost:5001").AllowCredentials().AllowAnyHeader().AllowAnyMethod(); }); }); @@ -58,17 +52,12 @@ public void ConfigureServices(IServiceCollection services) d.UseChallengeOnAuth = true; d.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; d.UseAuth = true; - d.DefaultAuthenticationScheme = "MyDashboardScheme"; + d.DefaultAuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;// "MyDashboardScheme"; // only if you want to apply policy authorization filter to CAP Dashboard user //d.AuthorizationPolicy = "PolicyCap"; }); - cap.UseMySql("server=192.168.3.57;port=3307;database=cap;UserId=root;Password=123123;"); - cap.UseRabbitMQ(aa => - { - aa.HostName = "192.168.3.57"; - aa.UserName = "user"; - aa.Password = "wJ0p5gSs17"; - }); + cap.UseInMemoryStorage(); + cap.UseInMemoryMessageQueue(); //cap.UseDiscovery(_ => //{ // _.DiscoveryServerHostName = "localhost";