Skip to content

Commit ce697be

Browse files
committed
Allow to configure authentication with multiple schemes
1 parent 5748ca5 commit ce697be

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

sample/Sample.Test.Splecflow/Sample.Test.Splecflow.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
17-
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
18-
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
19-
<PackageReference Include="SpecFlow" Version="2.2.0" />
20-
<PackageReference Include="SpecFlow.NetCore" Version="1.0.0-rc8" />
21-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
17+
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
18+
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
19+
<PackageReference Include="SpecFlow" Version="2.2.1" />
20+
<PackageReference Include="SpecFlow.NetCore" Version="1.2.0" />
21+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

sample/Sample.Test/Sample.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
15-
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
15+
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

sample/Sample.Web/Sample.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/GeekLearning.Testavior.Configuration/GeekLearning.Testavior.Configuration.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" />
19-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.1" />
19+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.1" />
2020
</ItemGroup>
2121

2222
</Project>
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
namespace GeekLearning.Testavior.Authentication
22
{
33
using Microsoft.AspNetCore.Authentication;
4-
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.Extensions.DependencyInjection.Extensions;
6-
using Microsoft.Extensions.Options;
74
using System;
85

96
public static class TestAuthenticationExtensions
@@ -12,5 +9,15 @@ public static AuthenticationBuilder AddTestAuthentication(this AuthenticationBui
129
{
1310
return builder.AddScheme<TestAuthenticationOptions, TestAuthenticationHandler>(authenticationScheme, displayName, configureOptions);
1411
}
12+
13+
public static AuthenticationBuilder AddTestAuthentication(this AuthenticationBuilder builder, string[] authenticationSchemes, string displayName, Action<TestAuthenticationOptions> configureOptions)
14+
{
15+
foreach (var authenticationScheme in authenticationSchemes)
16+
{
17+
builder = builder.AddScheme<TestAuthenticationOptions, TestAuthenticationHandler>(authenticationScheme, displayName, configureOptions);
18+
}
19+
20+
return builder;
21+
}
1522
}
1623
}

src/GeekLearning.Testavior/Environment/TestStartupConfigurationService.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.DependencyInjection;
1111
using Microsoft.Extensions.Logging;
12-
using Microsoft.Extensions.Options;
1312
using Mvc;
1413
using System;
14+
using System.Linq;
1515
using System.Security.Claims;
1616

1717
public class TestStartupConfigurationService<TDbContext> : IStartupConfigurationService
@@ -69,14 +69,18 @@ protected virtual void ConfigureStore(IServiceCollection services)
6969
services.AddDbContext<TDbContext>(options => options.UseSqlite(connection));
7070
}
7171

72-
protected virtual void ConfigureAuthentication(IServiceCollection services, string authenticationDefaultScheme = "Test")
72+
protected virtual void ConfigureAuthentication(IServiceCollection services, params string[] authenticationDefaultSchemes)
7373
{
74+
if (authenticationDefaultSchemes?.Any() != true)
75+
{
76+
authenticationDefaultSchemes = new string[] { "Test" };
77+
}
78+
7479
services.AddAuthentication(o =>
7580
{
76-
o.DefaultAuthenticateScheme = authenticationDefaultScheme;
77-
o.DefaultChallengeScheme = authenticationDefaultScheme;
81+
o.DefaultScheme = authenticationDefaultSchemes.First();
7882
})
79-
.AddTestAuthentication(authenticationDefaultScheme, "Test Authentication Scheme", o =>
83+
.AddTestAuthentication(authenticationDefaultSchemes, "Test Authentication Scheme", o =>
8084
{
8185
o.Identity = ConfigureIdentity();
8286
});

src/GeekLearning.Testavior/GeekLearning.Testavior.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="2.0.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0" />
25-
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
23+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="2.0.1" />
24+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.1" />
25+
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.1" />
26+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
2727
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
2828
</ItemGroup>
2929

0 commit comments

Comments
 (0)