47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace AzureADSample
|
|
{
|
|
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)
|
|
{
|
|
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
|
|
.AddAzureAD(options => Configuration.GetSection("AzureAD").Bind(options));
|
|
|
|
services.AddAuthorization(o => o.AddPolicy("Denied", new AuthorizationPolicyBuilder()
|
|
.RequireAuthenticatedUser()
|
|
.RequireAssertion(ahc => false)
|
|
.Build()));
|
|
|
|
services.AddMvc()
|
|
.AddRazorPagesOptions(o => o.Conventions.AuthorizePage("/About", "Denied"));
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseHttpsRedirection();
|
|
app.UseAuthentication();
|
|
app.UseStaticFiles();
|
|
app.UseMvcWithDefaultRoute();
|
|
}
|
|
}
|
|
}
|