Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit e687381

Browse files
committed
Make auth optional
1 parent c7c320c commit e687381

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics.Contracts;
7+
using System.Linq;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using Microsoft.AspNetCore.Authentication;
@@ -33,7 +34,7 @@ internal class MessagePump : IServer
3334

3435
private readonly ServerAddressesFeature _serverAddresses;
3536

36-
public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactory, IAuthenticationSchemeProvider authentication)
37+
public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactory, IEnumerable<IAuthenticationSchemeProvider> authentication)
3738
{
3839
if (options == null)
3940
{
@@ -43,16 +44,20 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
4344
{
4445
throw new ArgumentNullException(nameof(loggerFactory));
4546
}
46-
if (authentication == null)
47-
{
48-
throw new ArgumentNullException(nameof(authentication));
49-
}
50-
5147
_options = options.Value;
5248
Listener = new HttpSysListener(_options, loggerFactory);
5349
_logger = LogHelper.CreateLogger(loggerFactory, typeof(MessagePump));
5450

55-
AddSchemes(authentication, _options.Authentication.Schemes);
51+
if (_options.Authentication.Schemes != AuthenticationSchemes.None)
52+
{
53+
var auth = authentication.FirstOrDefault();
54+
if (auth == null)
55+
{
56+
throw new InvalidOperationException("AddAuthentication() is required to use Authentication.");
57+
}
58+
59+
AddSchemes(auth, _options.Authentication.Schemes);
60+
}
5661

5762
Features = new FeatureCollection();
5863
_serverAddresses = new ServerAddressesFeature();

src/Microsoft.AspNetCore.Server.HttpSys/Microsoft.AspNetCore.Server.HttpSys.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<PackageTags>aspnetcore;weblistener;httpsys</PackageTags>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.2.0-*" />
13-
<ProjectReference Include="..\..\..\Security\src\Microsoft.AspNetCore.Authentication.Impl\Microsoft.AspNetCore.Authentication.Impl.csproj" />
12+
<ProjectReference Include="..\..\..\Hosting\src\Microsoft.AspNetCore.Hosting\Microsoft.AspNetCore.Hosting.csproj" />
13+
<ProjectReference Include="..\..\..\Security\src\Microsoft.AspNetCore.Authentication\Microsoft.AspNetCore.Authentication.csproj" />
14+
<ProjectReference Include="..\..\..\Options\src\Microsoft.Extensions.Options\Microsoft.Extensions.Options.csproj" />
1415
<PackageReference Include="Microsoft.Extensions.RuntimeEnvironment.Sources" Version="1.2.0-*" PrivateAssets="All" />
1516
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="1.2.0-*" PrivateAssets="All" />
1617
<PackageReference Include="Microsoft.Net.Http.Headers" Version="1.2.0-*" />

0 commit comments

Comments
 (0)