// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { AzureAdModel azureAdModel = new AzureAdModel(); Configuration.Bind("AzureActiveDirectory", azureAdModel); services.AddOptions(); IConfigurationSection azureAdOption = Configuration.GetSection("AzureActiveDirectory"); IConfigurationSection targetApiOption = Configuration.GetSection("TargetApi"); services.Configure <AzureAdModel>(azureAdOption); services.Configure <TargetApiModel>(targetApiOption); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.AccessDeniedPath = new PathString("/AccessDenied"); }) .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => { options.Authority = azureAdModel.Authority; options.ClientId = azureAdModel.ClientId; options.ClientSecret = azureAdModel.ClientSecret; options.CallbackPath = azureAdModel.CallbackPath; options.Resource = azureAdModel.Resource; options.ResponseType = OidcConstants.ResponseTypes.CodeIdToken; options.SaveTokens = true; options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.Events.OnAuthorizationCodeReceived += HandleApiToken; }); services.AddDistributedMemoryCache(); services.AddControllersWithViews(); }
public Startup(IConfiguration configuration) { Configuration = configuration; _azOptions = new AzureAdModel(); }