76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using IdentityModel;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using Yavsc;
|
|
|
|
public class Startup
|
|
{
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
|
|
services.AddControllersWithViews();
|
|
services
|
|
.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = "Cookies";
|
|
options.DefaultChallengeScheme = "oidc";
|
|
})
|
|
.AddCookie("Cookies")
|
|
.AddOpenIdConnect("oidc", options =>
|
|
{
|
|
options.Authority = "https://localhost:5001";
|
|
|
|
options.ClientId = "mvc";
|
|
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";
|
|
options.ResponseType = "code";
|
|
|
|
options.Scope.Add("scope2");
|
|
|
|
options.SaveTokens = true;
|
|
|
|
options.GetClaimsFromUserInfoEndpoint = true;
|
|
options.SaveTokens = true;
|
|
options.ClaimActions.MapUniqueJsonKey(
|
|
Constants.RoleClaimName,
|
|
Constants.RoleClaimName);
|
|
options.ClaimActions.MapUniqueJsonKey(
|
|
JwtClaimTypes.Scope,
|
|
JwtClaimTypes.Scope);
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
NameClaimType = "name",
|
|
RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
|
|
};
|
|
});
|
|
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapDefaultControllerRoute()
|
|
.RequireAuthorization();
|
|
});
|
|
}
|
|
}
|