From 93fb1036bcbd7a4fd6eb97c67950a223de4360de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Thu, 29 Oct 2015 01:30:35 +0100 Subject: [PATCH] React to API changes in aspnet/Security https://github.com/aspnet/Security/commit/409b50269a9d85618a31f84a3ffc2868abb3eeea https://github.com/aspnet/Security/commit/35b724873402849b73ab28e919f5994365195126 https://github.com/aspnet/Security/commit/57a64298c05044802ae2db3e93bae270840ba149 --- samples/Mvc.Client/Startup.cs | 18 ++++-------------- samples/Mvc.Server/Startup.cs | 25 +++++-------------------- samples/Mvc.Server/project.json | 2 ++ 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/samples/Mvc.Client/Startup.cs b/samples/Mvc.Client/Startup.cs index 07e120c4..2b35b43f 100644 --- a/samples/Mvc.Client/Startup.cs +++ b/samples/Mvc.Client/Startup.cs @@ -1,12 +1,9 @@ -using System; using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Mvc.Client { @@ -20,14 +17,15 @@ namespace Mvc.Client { services.AddMvc(); } - public void Configure(IApplicationBuilder app, IRuntimeEnvironment environment) { + public void Configure(IApplicationBuilder app) { var factory = app.ApplicationServices.GetRequiredService(); factory.AddConsole(); // Insert a new cookies middleware in the pipeline to store the user // identity after he has been redirected from the identity provider. app.UseCookieAuthentication(options => { - options.AutomaticAuthentication = true; + options.AutomaticAuthenticate = true; + options.AutomaticChallenge = true; options.LoginPath = new PathString("/signin"); }); @@ -36,8 +34,8 @@ namespace Mvc.Client { // inserted in the database at the server level. options.ClientId = "myClient"; options.ClientSecret = "secret_secret_secret"; - options.RedirectUri = "http://localhost:53507/oidc"; options.PostLogoutRedirectUri = "http://localhost:53507/"; + options.RequireHttpsMetadata = false; // Use the authorization code flow. options.ResponseType = OpenIdConnectResponseTypes.Code; @@ -52,14 +50,6 @@ namespace Mvc.Client { options.Resource = "http://localhost:54540/"; 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( - metadataAddress: options.Authority + ".well-known/openid-configuration", - configRetriever: new OpenIdConnectConfigurationRetriever(), - docRetriever: new HttpDocumentRetriever { RequireHttps = false }); }); app.UseStaticFiles(); diff --git a/samples/Mvc.Server/Startup.cs b/samples/Mvc.Server/Startup.cs index 0daa3a5f..8429e98e 100644 --- a/samples/Mvc.Server/Startup.cs +++ b/samples/Mvc.Server/Startup.cs @@ -2,35 +2,27 @@ using System.Linq; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Protocols; -using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Mvc.Server.Models; using Mvc.Server.Services; using OpenIddict.Models; namespace Mvc.Server { public class Startup { - public Startup(IApplicationEnvironment environment) { - Configuration = new ConfigurationBuilder() - .SetBasePath(environment.ApplicationBasePath) + public void ConfigureServices(IServiceCollection services) { + var configuration = new ConfigurationBuilder() .AddJsonFile("config.json") .AddEnvironmentVariables() .Build(); - } - - public IConfiguration Configuration { get; } - public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddEntityFramework() .AddSqlServer() .AddDbContext(options => - options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); + options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"])); services.AddIdentity() .AddEntityFrameworkStores() @@ -52,14 +44,7 @@ namespace Mvc.Server { app.UseJwtBearerAuthentication(options => { options.Audience = "http://localhost:54540/"; options.Authority = "http://localhost:54540/"; - - // 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( - metadataAddress: options.Authority + ".well-known/openid-configuration", - configRetriever: new OpenIdConnectConfigurationRetriever(), - docRetriever: new HttpDocumentRetriever { RequireHttps = false }); + options.RequireHttpsMetadata = false; }); app.UseIdentity(); @@ -88,7 +73,7 @@ namespace Mvc.Server { context.Applications.Add(new Application { ApplicationID = "myClient", DisplayName = "My client application", - RedirectUri = "http://localhost:53507/oidc", + RedirectUri = "http://localhost:53507/signin-oidc", LogoutRedirectUri = "http://localhost:53507/", Secret = "secret_secret_secret", Type = ApplicationType.Confidential diff --git a/samples/Mvc.Server/project.json b/samples/Mvc.Server/project.json index 8a53be4f..b26e4b87 100644 --- a/samples/Mvc.Server/project.json +++ b/samples/Mvc.Server/project.json @@ -13,6 +13,8 @@ "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", + "EntityFramework.MicrosoftSqlServer": "7.0.0-*", + "Microsoft.Extensions.Logging.Console": "1.0.0-*", "OpenIddict": "1.0.0-*"