aspnetcore/template_feed/Microsoft.DotNet.Web.Projec.../content/WebApi-CSharp/Startup.cs

60 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
#if (OrganizationalAuth || IndividualB2CAuth)
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
#endif
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Company.WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
#if (OrganizationalAuth || IndividualB2CAuth)
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
#if (IndividualB2CAuth)
.AddAzureAdB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
#elseif (OrganizationalAuth)
.AddAzureAdBearer(options => Configuration.Bind("AzureAd", options));
#endif
#endif
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
#if (OrganizationalAuth || IndividualAuth)
app.UseAuthentication();
#endif
app.UseMvc();
}
}
}