You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By [Scott Addie](https://twitter.com/Scott_Addie) and [Luke Latham](https://github.com/guardrex)
14
14
15
-
[Windows Authentication](/iis/configuration/system.webServer/security/authentication/windowsAuthentication/) can be configured for ASP.NET Core apps hosted with [IIS](xref:host-and-deploy/iis/index) or [HTTP.sys](xref:fundamentals/servers/httpsys).
15
+
::: moniker range=">= aspnetcore-3.0"
16
+
17
+
Windows Authentication (A.K.A. Negotiate, Kerberos, or NTLM) can be configured for ASP.NET Core apps hosted with [IIS](xref:host-and-deploy/iis/index), [Kestrel](xref:fundamentals/servers/kestrel), or [HTTP.sys](xref:fundamentals/servers/httpsys).
18
+
19
+
::: moniker-end
20
+
21
+
::: moniker range="< aspnetcore-3.0"
22
+
23
+
Windows Authentication (A.K.A. Negotiate, Kerberos, or NTLM) can be configured for ASP.NET Core apps hosted with [IIS](xref:host-and-deploy/iis/index) or [HTTP.sys](xref:fundamentals/servers/httpsys).
24
+
25
+
::: moniker-end
16
26
17
27
Windows Authentication relies on the operating system to authenticate users of ASP.NET Core apps. You can use Windows Authentication when your server runs on a corporate network using Active Directory domain identities or Windows accounts to identify users. Windows Authentication is best suited to intranet environments where users, client apps, and web servers belong to the same Windows domain.
18
28
29
+
> [!NOTE]
30
+
> Windows Authentication is not supported on HTTP/2. These components allow authentication challenges to be sent on HTTP/2 responses and require the client to downgrade to HTTP/1.1 before authenticating.
31
+
19
32
## IIS/IIS Express
20
33
21
34
Add authentication services by invoking <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication*> (<xref:Microsoft.AspNetCore.Server.IISIntegration?displayProperty=fullName> namespace) in `Startup.ConfigureServices`:
@@ -119,9 +132,66 @@ Use **either** of the following approaches:
119
132
* Use IIS Manager to reset the settings in the *web.config* file after the file is overwritten on deployment.
120
133
* Add a *web.config file* to the app locally with the settings.
121
134
135
+
::: moniker range=">= aspnetcore-3.0"
136
+
137
+
## Kestrel
138
+
139
+
The [Microsoft.AspNetCore.Authentication.Negotiate](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Negotiate) nuget package can be used with [Kestrel](xref:fundamentals/servers/kestrel) to support Windows authentication using Negotiate, Kerberos, and NTLM on Windows, Linux, and Mac.
140
+
141
+
> [!WARNING]
142
+
> This component can persist credentials across requests on a given connection and MUST NOT be used with proxies unless they maintain a 1:1 connection affinity. This means it must not be used with Kestrel behind IIS ASP.NET Core Module (ANCM) out-of-proc.
143
+
144
+
Add authentication services by invoking <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication*> (<xref:Microsoft.AspNetCore.Authentication.Negotiate?displayProperty=fullName> namespace) and <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddNegotitate*> (<xref:Microsoft.AspNetCore.Authentication.Negotiate?displayProperty=fullName> namespace) in `Startup.ConfigureServices`:
Then add the Authentication [middleware](xref:fundamentals/middleware/index) by calling [UseAuthentication](/dotnet/api/microsoft.aspnetcore.builder.authappbuilderextensions.useauthentication#Microsoft_AspNetCore_Builder_AuthAppBuilderExtensions_UseAuthentication_Microsoft_AspNetCore_Builder_IApplicationBuilder_) in `Startup.Configure`.
152
+
153
+
```csharp
154
+
app.UseAuthentication();
155
+
156
+
app.UseMvc();
157
+
```
158
+
159
+
Anonymous requests are allowed by this component. Use [Authorization](xref:security/authorization/introduction) to challenge anonymous requests for authentication.
160
+
161
+
### Environment configuration
162
+
163
+
Some operating system specific configuration is required.
164
+
165
+
#### Windows
166
+
167
+
The [Microsoft.AspNetCore.Authentication.Negotiate](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Negotiate) component does user mode authentication so on Windows the SPNs must be added to the user account running the service, not the machine account. Call `setspn -S HTTP/mysrevername.mydomain.com myuser` from an admin command prompt.
168
+
169
+
#### Linux and Mac
170
+
171
+
Instructions for joining a Linux or Mac machine to a Windows domain can be found at [here](https://docs.microsoft.com/en-us/sql/azure-data-studio/enable-kerberos?view=sql-server-2017#join-your-os-to-the-active-directory-domain-controller). Those instructions create a machine account for the Linux machine on the domain. SPNs will need to be added to that SPN account.
172
+
173
+
> [!NOTE]
174
+
> The Linux instructions were tested with Ubuntu 18.04 and the install list is outdated. Replace python-software-properties with python3-software-properties if needed.
175
+
176
+
Once the Linux or Mac machine is joined to the domain a few additional steps are required to provide a keytab file with the SPNs:
177
+
- On the domain controller add new SPNs for the web service to the machine account:
- Some fields must be specified in UPPER CASE as indicated.
183
+
- Copy that keytab file to the linux machine.
184
+
- Select that keytab via environment variable: `export KRB5_KTNAME=/tmp/mymachine.HTTP.keytab`
185
+
- Invoke `klist` to show the SPNs currently available for use.
186
+
187
+
> [!NOTE]
188
+
> A keytab file contains domain access credentials and should be protected accordingly.
189
+
190
+
::: moniker-end
191
+
122
192
## HTTP.sys
123
193
124
-
In self-hosted scenarios, [Kestrel](xref:fundamentals/servers/kestrel) doesn't support Windows Authentication, but you can use [HTTP.sys](xref:fundamentals/servers/httpsys).
194
+
[HTTP.sys](xref:fundamentals/servers/httpsys) supports kernel mode Windows authentication using Negotiate, NTLM, or Basic authentication.
125
195
126
196
Add authentication services by invoking <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication*> (<xref:Microsoft.AspNetCore.Server.HttpSys?displayProperty=fullName> namespace) in `Startup.ConfigureServices`:
127
197
@@ -172,6 +242,12 @@ ASP.NET Core doesn't implement impersonation. Apps run with the app's identity f
172
242
173
243
`RunImpersonated` doesn't support asynchronous operations and shouldn't be used for complex scenarios. For example, wrapping entire requests or middleware chains isn't supported or recommended.
174
244
245
+
::: moniker range=">= aspnetcore-3.0"
246
+
247
+
While the [Microsoft.AspNetCore.Authentication.Negotiate](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Negotiate) package enables authentication on Windows, Linux and Mac, impersonation is only supported on Windows.
248
+
249
+
::: moniker-end
250
+
175
251
## Claims transformations
176
252
177
253
When hosting with IIS in-process mode, <xref:Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync*> isn't called internally to initialize a user. Therefore, an <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation> implementation used to transform claims after every authentication isn't activated by default. For more information and a code example that activates claims transformations when hosting in-process, see <xref:host-and-deploy/aspnet-core-module#in-process-hosting-model>.
0 commit comments