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.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<ILoggerFactory>();
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<OpenIdConnectConfiguration>(
metadataAddress: options.Authority + ".well-known/openid-configuration",
configRetriever: new OpenIdConnectConfigurationRetriever(),
docRetriever: new HttpDocumentRetriever { RequireHttps = false });
});
app.UseStaticFiles();

25
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<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
@ -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<OpenIdConnectConfiguration>(
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

2
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-*"

Loading…
Cancel
Save