From 2f10eea077cc999af45ddefe56acefbb43c426b5 Mon Sep 17 00:00:00 2001 From: Rick Anderson Date: Fri, 27 Oct 2017 15:39:09 -1000 Subject: [PATCH 1/3] Update dependency-injection.md (#4647) --- aspnetcore/fundamentals/dependency-injection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/dependency-injection.md b/aspnetcore/fundamentals/dependency-injection.md index d3e86ffc4a..9a14d76dfa 100644 --- a/aspnetcore/fundamentals/dependency-injection.md +++ b/aspnetcore/fundamentals/dependency-injection.md @@ -291,7 +291,7 @@ When working with dependency injection, keep the following recommendations in mi * DI is for objects that have complex dependencies. Controllers, services, adapters, and repositories are all examples of objects that might be added to DI. -* Avoid storing data and configuration directly in DI. For example, a user's shopping cart shouldn't typically be added to the services container. Configuration should use the [Options Model](configuration.md#options-config-objects). Similarly, avoid "data holder" objects that only exist to allow access to some other object. It's better to request the actual item needed via DI, if possible. +* Avoid storing data and configuration directly in DI. For example, a user's shopping cart shouldn't typically be added to the services container. Configuration should use the [Options Model](configuration.md#using-options-and-configuration-objects). Similarly, avoid "data holder" objects that only exist to allow access to some other object. It's better to request the actual item needed via DI, if possible. * Avoid static access to services. From a2da468c89c9b0dee95a726c94e32e973086e125 Mon Sep 17 00:00:00 2001 From: Rick Anderson Date: Fri, 27 Oct 2017 15:39:52 -1000 Subject: [PATCH 2/3] Do not merge: Test build (#4645) --- aspnetcore/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/index.md b/aspnetcore/index.md index 3f04c18244..9131ea6268 100644 --- a/aspnetcore/index.md +++ b/aspnetcore/index.md @@ -1,7 +1,7 @@ --- title: Introduction to ASP.NET Core author: rick-anderson -description: +description: Provides an introduction to ASP.NET Core. keywords: ASP.NET Core, ms.author: riande manager: wpickett From a40eeb13a1fd6afa56622cb370b4fe62b367782e Mon Sep 17 00:00:00 2001 From: Scott Addie Date: Fri, 27 Oct 2017 21:07:57 -0500 Subject: [PATCH 3/3] Fix incorrect 2.0 reference to AuthenticationOptions (#4631) * Fix incorrect 2.0 reference to AuthenticationOptions * More tweaks --- aspnetcore/migration/1x-to-2x/identity-2x.md | 38 +++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/aspnetcore/migration/1x-to-2x/identity-2x.md b/aspnetcore/migration/1x-to-2x/identity-2x.md index 350c67145a..1e21b40b6a 100644 --- a/aspnetcore/migration/1x-to-2x/identity-2x.md +++ b/aspnetcore/migration/1x-to-2x/identity-2x.md @@ -5,7 +5,7 @@ description: This article outlines the most common steps for migrating ASP.NET C keywords: ASP.NET Core,Identity,authentication ms.author: scaddie manager: wpickett -ms.date: 08/02/2017 +ms.date: 10/26/2017 ms.topic: article ms.technology: aspnet ms.prod: asp.net-core @@ -55,7 +55,8 @@ public void ConfigureServices(IServiceCollection services) // If you want to tweak Identity cookies, they're no longer part of IdentityOptions. services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/LogIn"); services.AddAuthentication() - .AddFacebook(options => { + .AddFacebook(options => + { options.AppId = Configuration["auth:facebook:appid"]; options.AppSecret = Configuration["auth:facebook:appsecret"]; }); @@ -104,7 +105,8 @@ Select one of the two options below, and make the necessary changes in *Startup. // If you don't want the cookie to be automatically authenticated and assigned to HttpContext.User, // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) - .AddCookie(options => { + .AddCookie(options => + { options.LoginPath = "/Account/LogIn"; options.LogoutPath = "/Account/LogOff"; }); @@ -122,7 +124,8 @@ Make the following changes in *Startup.cs*: ```csharp services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => { + .AddJwtBearer(options => + { options.Audience = "http://localhost:5001/"; options.Authority = "http://localhost:5000/"; }); @@ -142,12 +145,14 @@ Make the following changes in *Startup.cs*: - Invoke the `AddOpenIdConnect` method in the `ConfigureServices` method: ```csharp - services.AddAuthentication(options => { + services.AddAuthentication(options => + { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddCookie() - .AddOpenIdConnect(options => { + .AddOpenIdConnect(options => + { options.Authority = Configuration["auth:oidc:authority"]; options.ClientId = Configuration["auth:oidc:clientid"]; }); @@ -165,7 +170,8 @@ Make the following changes in *Startup.cs*: ```csharp services.AddAuthentication() - .AddFacebook(options => { + .AddFacebook(options => + { options.AppId = Configuration["auth:facebook:appid"]; options.AppSecret = Configuration["auth:facebook:appsecret"]; }); @@ -183,7 +189,8 @@ Make the following changes in *Startup.cs*: ```csharp services.AddAuthentication() - .AddGoogle(options => { + .AddGoogle(options => + { options.ClientId = Configuration["auth:google:clientid"]; options.ClientSecret = Configuration["auth:google:clientsecret"]; }); @@ -201,7 +208,8 @@ Make the following changes in *Startup.cs*: ```csharp services.AddAuthentication() - .AddMicrosoftAccount(options => { + .AddMicrosoftAccount(options => + { options.ClientId = Configuration["auth:microsoft:clientid"]; options.ClientSecret = Configuration["auth:microsoft:clientsecret"]; }); @@ -219,25 +227,29 @@ Make the following changes in *Startup.cs*: ```csharp services.AddAuthentication() - .AddTwitter(options => { + .AddTwitter(options => + { options.ConsumerKey = Configuration["auth:twitter:consumerkey"]; options.ConsumerSecret = Configuration["auth:twitter:consumersecret"]; }); ``` ### Setting Default Authentication Schemes -In 1.x, the `AutomaticAuthenticate` and `AutomaticChallenge` properties were intended to be set on a single authentication scheme. There was no good way to enforce this. +In 1.x, the `AutomaticAuthenticate` and `AutomaticChallenge` properties of the [AuthenticationOptions](https://docs.microsoft.com/dotnet/api/Microsoft.AspNetCore.Builder.AuthenticationOptions?view=aspnetcore-1.1) base class were intended to be set on a single authentication scheme. There was no good way to enforce this. -In 2.0, these two properties have been removed as flags on the individual `AuthenticationOptions` instance and have moved into the base [AuthenticationOptions](/aspnet/core/api/microsoft.aspnetcore.builder.authenticationoptions) class. The properties can be configured in the `AddAuthentication` method call within the `ConfigureServices` method of *Startup.cs*: +In 2.0, these two properties have been removed as properties on the individual `AuthenticationOptions` instance. They can be configured in the `AddAuthentication` method call within the `ConfigureServices` method of *Startup.cs*: ```csharp services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme); ``` +In the preceding code snippet, the default scheme is set to `CookieAuthenticationDefaults.AuthenticationScheme` ("Cookies"). + Alternatively, use an overloaded version of the `AddAuthentication` method to set more than one property. In the following overloaded method example, the default scheme is set to `CookieAuthenticationDefaults.AuthenticationScheme`. The authentication scheme may alternatively be specified within your individual `[Authorize]` attributes or authorization policies. ```csharp -services.AddAuthentication(options => { +services.AddAuthentication(options => +{ options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; });