isn/Startup.cs

80 lines
2.6 KiB
C#
Raw Normal View History

2021-04-08 02:03:17 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2021-04-08 03:08:20 +01:00
using Microsoft.AspNetCore.Authentication.JwtBearer;
2021-04-08 02:03:17 +01:00
using Microsoft.AspNetCore.Builder;
2021-04-08 03:08:20 +01:00
using Microsoft.AspNetCore.DataProtection;
2021-04-08 02:03:17 +01:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace nuget_host
{
public class Startup
{
2021-04-08 03:08:20 +01:00
public Startup(IConfiguration config)
2021-04-08 02:03:17 +01:00
{
Configuration = config;
}
public IConfiguration Configuration { get; }
public static string ExternalUrl { get; private set; }
public static string SourceDir { get; private set; }
2021-04-08 03:08:20 +01:00
public static string RootApiKeySecret { get; private set; }
2021-04-08 02:03:17 +01:00
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
2021-04-08 03:08:20 +01:00
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
// base-address of your identityserver
options.Authority = ExternalUrl;
// if you are using API resources, you can specify the name here
options.Audience = "packages";
2021-04-10 14:11:09 +01:00
});
2021-04-08 02:03:17 +01:00
services.AddMvc();
2021-04-08 03:08:20 +01:00
services.AddDataProtection();
2021-04-10 14:11:09 +01:00
services.AddIdentityServer()
.AddInMemoryClients(Config.Clients)
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryApiResources(Config.ApiResources)
.AddDeveloperSigningCredential()
.AddTestUsers(Config.TestUsers);
2021-04-08 02:03:17 +01:00
}
// 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())
{
2021-04-10 14:11:09 +01:00
app.UseDeveloperExceptionPage();
2021-04-08 02:03:17 +01:00
}
else
{
app.UseExceptionHandler("/Home/Error");
}
ExternalUrl = Configuration["NuGet:ExternalUrl"];
SourceDir = Configuration["NuGet:SourceDir"];
2021-04-08 03:08:20 +01:00
RootApiKeySecret = Configuration["RootApiKeySecret"];
2021-04-08 02:03:17 +01:00
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}