Browse Source

React to API changes in aspnet/Security

409b50269a

35b7248734

57a64298c0
pull/27/merge
Kévin Chalet 10 years ago
parent
commit
93fb1036bc
  1. 18
      samples/Mvc.Client/Startup.cs
  2. 25
      samples/Mvc.Server/Startup.cs
  3. 2
      samples/Mvc.Server/project.json

18
samples/Mvc.Client/Startup.cs

@ -1,12 +1,9 @@
using System;
using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authentication;
using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Dnx.Runtime;
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 Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace Mvc.Client { namespace Mvc.Client {
@ -20,14 +17,15 @@ namespace Mvc.Client {
services.AddMvc(); services.AddMvc();
} }
public void Configure(IApplicationBuilder app, IRuntimeEnvironment environment) { public void Configure(IApplicationBuilder app) {
var factory = app.ApplicationServices.GetRequiredService<ILoggerFactory>(); var factory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
factory.AddConsole(); factory.AddConsole();
// Insert a new cookies middleware in the pipeline to store the user // Insert a new cookies middleware in the pipeline to store the user
// identity after he has been redirected from the identity provider. // identity after he has been redirected from the identity provider.
app.UseCookieAuthentication(options => { app.UseCookieAuthentication(options => {
options.AutomaticAuthentication = true; options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.LoginPath = new PathString("/signin"); options.LoginPath = new PathString("/signin");
}); });
@ -36,8 +34,8 @@ namespace Mvc.Client {
// inserted in the database at the server level. // inserted in the database at the server level.
options.ClientId = "myClient"; options.ClientId = "myClient";
options.ClientSecret = "secret_secret_secret"; options.ClientSecret = "secret_secret_secret";
options.RedirectUri = "http://localhost:53507/oidc";
options.PostLogoutRedirectUri = "http://localhost:53507/"; options.PostLogoutRedirectUri = "http://localhost:53507/";
options.RequireHttpsMetadata = false;
// Use the authorization code flow. // Use the authorization code flow.
options.ResponseType = OpenIdConnectResponseTypes.Code; options.ResponseType = OpenIdConnectResponseTypes.Code;
@ -52,14 +50,6 @@ namespace Mvc.Client {
options.Resource = "http://localhost:54540/"; options.Resource = "http://localhost:54540/";
options.Scope.Add("email"); options.Scope.Add("email");
// 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.UseStaticFiles(); app.UseStaticFiles();

25
samples/Mvc.Server/Startup.cs

@ -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

2
samples/Mvc.Server/project.json

@ -13,6 +13,8 @@
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*",
"EntityFramework.MicrosoftSqlServer": "7.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*",
"OpenIddict": "1.0.0-*" "OpenIddict": "1.0.0-*"

Loading…
Cancel
Save