Startup.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Microsoft.AspNetCore.Authentication;
  2. using Microsoft.AspNetCore.Authentication.AzureAD.UI;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.HttpsPolicy;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Hosting;
  10. using Microsoft.Extensions.Logging;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Threading.Tasks;
  15. namespace Services
  16. {
  17. public class Startup
  18. {
  19. public Startup(IConfiguration configuration)
  20. {
  21. Configuration = configuration;
  22. }
  23. public IConfiguration Configuration { get; }
  24. // This method gets called by the runtime. Use this method to add services to the container.
  25. public void ConfigureServices(IServiceCollection services)
  26. {
  27. services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
  28. .AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
  29. services.AddControllers();
  30. }
  31. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  32. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  33. {
  34. if (env.IsDevelopment())
  35. {
  36. app.UseDeveloperExceptionPage();
  37. }
  38. app.UseHttpsRedirection();
  39. app.UseRouting();
  40. app.UseAuthentication();
  41. app.UseAuthorization();
  42. app.UseEndpoints(endpoints =>
  43. {
  44. endpoints.MapControllers();
  45. });
  46. }
  47. }
  48. }