You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 rivejä
3.4 KiB

  1. using Microsoft.AspNetCore.Authentication.Cookies;
  2. using Microsoft.AspNetCore.Authentication.OpenIdConnect;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.Extensions.DependencyInjection;
  6. namespace Sample.Dashboard.Auth
  7. {
  8. public class Startup
  9. {
  10. private readonly IConfiguration _configuration;
  11. public Startup(IConfiguration configuration)
  12. {
  13. _configuration = configuration;
  14. }
  15. public void ConfigureServices(IServiceCollection services)
  16. {
  17. services
  18. .AddAuthorization()
  19. .AddAuthentication(options =>
  20. {
  21. options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  22. options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  23. })
  24. .AddCookie()
  25. .AddOpenIdConnect(options =>
  26. {
  27. options.Authority = "https://demo.identityserver.io/";
  28. options.ClientId = "interactive.confidential";
  29. options.ClientSecret = "secret";
  30. options.ResponseType = "code";
  31. options.UsePkce = true;
  32. options.Scope.Clear();
  33. options.Scope.Add("openid");
  34. options.Scope.Add("profile");
  35. })
  36. .AddScheme<MyDashboardAuthenticationSchemeOptions, MyDashboardAuthenticationHandler>("MyDashboardScheme",null);
  37. services.AddCors(x =>
  38. {
  39. x.AddDefaultPolicy(p =>
  40. {
  41. p.WithOrigins("http://localhost:8080").AllowCredentials().AllowAnyHeader().AllowAnyMethod();
  42. });
  43. });
  44. services.AddCap(cap =>
  45. {
  46. cap.UseDashboard(d =>
  47. {
  48. d.UseChallengeOnAuth = true;
  49. d.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  50. d.UseAuth = true;
  51. d.DefaultAuthenticationScheme = "MyDashboardScheme";
  52. });
  53. cap.UseMySql(_configuration.GetValue<string>("ConnectionString"));
  54. cap.UseRabbitMQ(aa =>
  55. {
  56. aa.HostName = "192.168.3.57";
  57. aa.UserName = "user";
  58. aa.Password = "wJ0p5gSs17";
  59. });
  60. //cap.UseDiscovery(_ =>
  61. //{
  62. // _.DiscoveryServerHostName = "localhost";
  63. // _.DiscoveryServerPort = 8500;
  64. // _.CurrentNodeHostName = _configuration.GetValue<string>("ASPNETCORE_HOSTNAME");
  65. // _.CurrentNodePort = _configuration.GetValue<int>("ASPNETCORE_PORT");
  66. // _.NodeId = _configuration.GetValue<string>("NodeId");
  67. // _.NodeName = _configuration.GetValue<string>("NodeName");
  68. //});
  69. });
  70. services.AddControllers();
  71. }
  72. public void Configure(IApplicationBuilder app)
  73. {
  74. app.UseCors();
  75. app.UseRouting();
  76. app.UseAuthentication();
  77. app.UseAuthorization();
  78. app.UseCookiePolicy();
  79. app.UseEndpoints(endpoints =>
  80. {
  81. endpoints.MapControllers();
  82. });
  83. }
  84. }
  85. }