|
|
@ -2,35 +2,27 @@ using System.Linq; |
|
|
using Microsoft.AspNet.Builder; |
|
|
using Microsoft.AspNet.Builder; |
|
|
using Microsoft.AspNet.Identity.EntityFramework; |
|
|
using Microsoft.AspNet.Identity.EntityFramework; |
|
|
using Microsoft.Data.Entity; |
|
|
using Microsoft.Data.Entity; |
|
|
using Microsoft.Dnx.Runtime; |
|
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.IdentityModel.Protocols; |
|
|
|
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect; |
|
|
|
|
|
using Mvc.Server.Models; |
|
|
using Mvc.Server.Models; |
|
|
using Mvc.Server.Services; |
|
|
using Mvc.Server.Services; |
|
|
using OpenIddict.Models; |
|
|
using OpenIddict.Models; |
|
|
|
|
|
|
|
|
namespace Mvc.Server { |
|
|
namespace Mvc.Server { |
|
|
public class Startup { |
|
|
public class Startup { |
|
|
public Startup(IApplicationEnvironment environment) { |
|
|
public void ConfigureServices(IServiceCollection services) { |
|
|
Configuration = new ConfigurationBuilder() |
|
|
var configuration = new ConfigurationBuilder() |
|
|
.SetBasePath(environment.ApplicationBasePath) |
|
|
|
|
|
.AddJsonFile("config.json") |
|
|
.AddJsonFile("config.json") |
|
|
.AddEnvironmentVariables() |
|
|
.AddEnvironmentVariables() |
|
|
.Build(); |
|
|
.Build(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; } |
|
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services) { |
|
|
|
|
|
services.AddMvc(); |
|
|
services.AddMvc(); |
|
|
|
|
|
|
|
|
services.AddEntityFramework() |
|
|
services.AddEntityFramework() |
|
|
.AddSqlServer() |
|
|
.AddSqlServer() |
|
|
.AddDbContext<ApplicationDbContext>(options => |
|
|
.AddDbContext<ApplicationDbContext>(options => |
|
|
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); |
|
|
options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"])); |
|
|
|
|
|
|
|
|
services.AddIdentity<ApplicationUser, IdentityRole>() |
|
|
services.AddIdentity<ApplicationUser, IdentityRole>() |
|
|
.AddEntityFrameworkStores<ApplicationDbContext>() |
|
|
.AddEntityFrameworkStores<ApplicationDbContext>() |
|
|
@ -52,14 +44,7 @@ namespace Mvc.Server { |
|
|
app.UseJwtBearerAuthentication(options => { |
|
|
app.UseJwtBearerAuthentication(options => { |
|
|
options.Audience = "http://localhost:54540/"; |
|
|
options.Audience = "http://localhost:54540/"; |
|
|
options.Authority = "http://localhost:54540/"; |
|
|
options.Authority = "http://localhost:54540/"; |
|
|
|
|
|
options.RequireHttpsMetadata = false; |
|
|
// Note: by default, IdentityModel beta8 now refuses to initiate non-HTTPS calls.
|
|
|
|
|
|
// To work around this limitation, the configuration manager is manually
|
|
|
|
|
|
// instantiated with a document retriever allowing HTTP calls.
|
|
|
|
|
|
options.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>( |
|
|
|
|
|
metadataAddress: options.Authority + ".well-known/openid-configuration", |
|
|
|
|
|
configRetriever: new OpenIdConnectConfigurationRetriever(), |
|
|
|
|
|
docRetriever: new HttpDocumentRetriever { RequireHttps = false }); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
app.UseIdentity(); |
|
|
app.UseIdentity(); |
|
|
@ -88,7 +73,7 @@ namespace Mvc.Server { |
|
|
context.Applications.Add(new Application { |
|
|
context.Applications.Add(new Application { |
|
|
ApplicationID = "myClient", |
|
|
ApplicationID = "myClient", |
|
|
DisplayName = "My client application", |
|
|
DisplayName = "My client application", |
|
|
RedirectUri = "http://localhost:53507/oidc", |
|
|
RedirectUri = "http://localhost:53507/signin-oidc", |
|
|
LogoutRedirectUri = "http://localhost:53507/", |
|
|
LogoutRedirectUri = "http://localhost:53507/", |
|
|
Secret = "secret_secret_secret", |
|
|
Secret = "secret_secret_secret", |
|
|
Type = ApplicationType.Confidential |
|
|
Type = ApplicationType.Confidential |
|
|
|