adds aspnet.identity
This commit is contained in:
64
Startup.cs
64
Startup.cs
@ -2,12 +2,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using nuget_host.Data;
|
||||
using nuget_host.Interfaces;
|
||||
using nuget_host.Services;
|
||||
using nuget_host.Entities;
|
||||
using nuget_host.Models;
|
||||
|
||||
namespace nuget_host
|
||||
{
|
||||
@ -26,42 +36,51 @@ namespace nuget_host
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseNpgsql(
|
||||
Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddSignInManager()
|
||||
.AddDefaultUI()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.AddIdentityServer(options =>
|
||||
{
|
||||
// base-address of your identityserver
|
||||
options.Authority = ExternalUrl;
|
||||
options.Discovery.CustomEntries.Add("local_api", "~/localapi");
|
||||
})
|
||||
.AddAspNetIdentity<ApplicationUser>()
|
||||
.AddInMemoryClients(Config.Clients)
|
||||
.AddInMemoryIdentityResources(Config.IdentityResources)
|
||||
.AddInMemoryApiResources(Config.ApiResources)
|
||||
.AddDeveloperSigningCredential()
|
||||
.AddTestUsers(Config.TestUsers);
|
||||
|
||||
// if you are using API resources, you can specify the name here
|
||||
options.Audience = "packages";
|
||||
|
||||
});
|
||||
services.AddMvc();
|
||||
|
||||
services.AddDataProtection();
|
||||
services.AddTransient<IMailer, EmailSender>();
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
|
||||
services.AddIdentityServer()
|
||||
.AddInMemoryClients(Config.Clients)
|
||||
.AddInMemoryIdentityResources(Config.IdentityResources)
|
||||
.AddInMemoryApiResources(Config.ApiResources)
|
||||
.AddDeveloperSigningCredential()
|
||||
.AddTestUsers(Config.TestUsers);
|
||||
|
||||
var smtpSettingsconf = Configuration.GetSection("SmtpSettings");
|
||||
services.Configure<SmtpSettings>(smtpSettingsconf);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseMigrationsEndPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
ExternalUrl = Configuration["NuGet:ExternalUrl"];
|
||||
SourceDir = Configuration["NuGet:SourceDir"];
|
||||
@ -69,6 +88,11 @@ namespace nuget_host
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
|
Reference in New Issue
Block a user