From ae3dfcdb32647473e24f7c03aa6cb13e83bb7577 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 5 Jun 2017 11:34:35 -0700 Subject: [PATCH] Remote ConfigureDefaultOptions --- .../FacebookExtensions.cs | 7 +-- .../Internal/FacebookConfigureOptions.cs | 16 ----- ....AspNetCore.Authentication.Facebook.csproj | 1 - .../GoogleExtensions.cs | 7 +-- .../Internal/GoogleConfigureOptions.cs | 16 ----- ...ft.AspNetCore.Authentication.Google.csproj | 1 - .../Internal/JwtBearerConfigureOptions.cs | 17 ----- .../JwtBearerExtensions.cs | 3 - ...AspNetCore.Authentication.JwtBearer.csproj | 1 - .../MicrosoftAccountConfigureOptions.cs | 17 ----- ...ore.Authentication.MicrosoftAccount.csproj | 1 - .../MicrosoftAccountExtensions.cs | 7 +-- .../Internal/OpenIdConnectConfigureOptions.cs | 17 ----- ...etCore.Authentication.OpenIdConnect.csproj | 1 - .../OpenIdConnectExtensions.cs | 3 - .../Internal/TwitterConfigureOptions.cs | 17 ----- ...t.AspNetCore.Authentication.Twitter.csproj | 1 - .../TwitterExtensions.cs | 3 - .../FacebookTests.cs | 63 ------------------- .../GoogleTests.cs | 60 ------------------ .../JwtBearerTests.cs | 62 ------------------ .../MicrosoftAccountTests.cs | 60 ------------------ .../OpenIdConnect/OpenIdConnectTests.cs | 28 --------- .../TwitterTests.cs | 54 ---------------- 24 files changed, 3 insertions(+), 460 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Authentication.Facebook/Internal/FacebookConfigureOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Authentication.Google/Internal/GoogleConfigureOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Authentication.JwtBearer/Internal/JwtBearerConfigureOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Internal/MicrosoftAccountConfigureOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Internal/OpenIdConnectConfigureOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Authentication.Twitter/Internal/TwitterConfigureOptions.cs diff --git a/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs index 7d6fb84421..4f30b9ba9c 100644 --- a/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs @@ -3,8 +3,6 @@ using System; using Microsoft.AspNetCore.Authentication.Facebook; -using Microsoft.AspNetCore.Authentication.Facebook.Internal; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -17,9 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection => services.AddFacebookAuthentication(FacebookDefaults.AuthenticationScheme, configureOptions); public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.AddSingleton, FacebookConfigureOptions>(); - return services.AddOAuthAuthentication(authenticationScheme, configureOptions); - } + => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.Facebook/Internal/FacebookConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.Facebook/Internal/FacebookConfigureOptions.cs deleted file mode 100644 index df1ab710bd..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.Facebook/Internal/FacebookConfigureOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.Facebook.Internal -{ - public class FacebookConfigureOptions : ConfigureDefaultOptions - { - public FacebookConfigureOptions(IConfiguration config) : - base(FacebookDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+FacebookDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.Facebook/Microsoft.AspNetCore.Authentication.Facebook.csproj b/src/Microsoft.AspNetCore.Authentication.Facebook/Microsoft.AspNetCore.Authentication.Facebook.csproj index e39b31e904..a939958e27 100644 --- a/src/Microsoft.AspNetCore.Authentication.Facebook/Microsoft.AspNetCore.Authentication.Facebook.csproj +++ b/src/Microsoft.AspNetCore.Authentication.Facebook/Microsoft.AspNetCore.Authentication.Facebook.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs index 07d3e16d61..be40822c57 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs @@ -3,8 +3,6 @@ using System; using Microsoft.AspNetCore.Authentication.Google; -using Microsoft.AspNetCore.Authentication.Google.Internal; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -17,9 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection => services.AddGoogleAuthentication(GoogleDefaults.AuthenticationScheme, configureOptions); public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.AddSingleton, GoogleConfigureOptions>(); - return services.AddOAuthAuthentication(authenticationScheme, configureOptions); - } + => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.Google/Internal/GoogleConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.Google/Internal/GoogleConfigureOptions.cs deleted file mode 100644 index bbc5e208a7..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.Google/Internal/GoogleConfigureOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.Google.Internal -{ - public class GoogleConfigureOptions : ConfigureDefaultOptions - { - public GoogleConfigureOptions(IConfiguration config) : - base(GoogleDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+GoogleDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.Google/Microsoft.AspNetCore.Authentication.Google.csproj b/src/Microsoft.AspNetCore.Authentication.Google/Microsoft.AspNetCore.Authentication.Google.csproj index c4f1e7ad8f..9f4cee9d59 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/Microsoft.AspNetCore.Authentication.Google.csproj +++ b/src/Microsoft.AspNetCore.Authentication.Google/Microsoft.AspNetCore.Authentication.Google.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.JwtBearer/Internal/JwtBearerConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.JwtBearer/Internal/JwtBearerConfigureOptions.cs deleted file mode 100644 index 5c1e931f40..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.JwtBearer/Internal/JwtBearerConfigureOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.JwtBearer.Internal -{ - public class JwtBearerConfigureOptions : ConfigureDefaultOptions - { - // Bind to "Bearer" section by default - public JwtBearerConfigureOptions(IConfiguration config) : - base(JwtBearerDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+JwtBearerDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs b/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs index 134e99920b..582eb6314d 100644 --- a/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs @@ -3,10 +3,8 @@ using System; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authentication.JwtBearer.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -21,7 +19,6 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) { services.TryAddEnumerable(ServiceDescriptor.Singleton, JwtBearerPostConfigureOptions>()); - services.AddSingleton, JwtBearerConfigureOptions>(); return services.AddScheme(authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.JwtBearer/Microsoft.AspNetCore.Authentication.JwtBearer.csproj b/src/Microsoft.AspNetCore.Authentication.JwtBearer/Microsoft.AspNetCore.Authentication.JwtBearer.csproj index 5b25e00e86..73d8fdd008 100644 --- a/src/Microsoft.AspNetCore.Authentication.JwtBearer/Microsoft.AspNetCore.Authentication.JwtBearer.csproj +++ b/src/Microsoft.AspNetCore.Authentication.JwtBearer/Microsoft.AspNetCore.Authentication.JwtBearer.csproj @@ -11,7 +11,6 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Internal/MicrosoftAccountConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Internal/MicrosoftAccountConfigureOptions.cs deleted file mode 100644 index 60591e1e4a..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Internal/MicrosoftAccountConfigureOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.MicrosoftAccount.Internal -{ - public class MicrosoftAccountConfigureOptions : ConfigureDefaultOptions - { - // Bind to "Microsoft" section by default - public MicrosoftAccountConfigureOptions(IConfiguration config) : - base(MicrosoftAccountDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+MicrosoftAccountDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj index 1a954c850a..1accdf8f14 100644 --- a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj +++ b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs index ff743c9728..a4ad5692cd 100644 --- a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs @@ -3,8 +3,6 @@ using System; using Microsoft.AspNetCore.Authentication.MicrosoftAccount; -using Microsoft.AspNetCore.Authentication.MicrosoftAccount.Internal; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -17,9 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection => services.AddMicrosoftAccountAuthentication(MicrosoftAccountDefaults.AuthenticationScheme, configureOptions); public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.AddSingleton, MicrosoftAccountConfigureOptions>(); - return services.AddOAuthAuthentication(authenticationScheme, configureOptions); - } + => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Internal/OpenIdConnectConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Internal/OpenIdConnectConfigureOptions.cs deleted file mode 100644 index c395185151..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Internal/OpenIdConnectConfigureOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.OpenIdConnect.Internal -{ - internal class OpenIdConnectConfigureOptions : ConfigureDefaultOptions - { - // Bind to "OpenIdConnect" section by default - public OpenIdConnectConfigureOptions(IConfiguration config) : - base(OpenIdConnectDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+OpenIdConnectDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj index 0ce2fe34e0..8e4fb774db 100644 --- a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj +++ b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj @@ -12,6 +12,5 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs index 6c965f047c..d576409047 100644 --- a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs @@ -3,10 +3,8 @@ using System; using Microsoft.AspNetCore.Authentication.OpenIdConnect; -using Microsoft.AspNetCore.Authentication.OpenIdConnect.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -21,7 +19,6 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) { services.TryAddEnumerable(ServiceDescriptor.Singleton, OpenIdConnectPostConfigureOptions>()); - services.AddSingleton, OpenIdConnectConfigureOptions>(); return services.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.Twitter/Internal/TwitterConfigureOptions.cs b/src/Microsoft.AspNetCore.Authentication.Twitter/Internal/TwitterConfigureOptions.cs deleted file mode 100644 index 62982fa19a..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.Twitter/Internal/TwitterConfigureOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Authentication.Twitter.Internal -{ - public class TwitterConfigureOptions : ConfigureDefaultOptions - { - // Bind to "Twitter" section by default - public TwitterConfigureOptions(IConfiguration config) : - base(TwitterDefaults.AuthenticationScheme, - options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+TwitterDefaults.AuthenticationScheme).Bind(options)) - { } - } -} diff --git a/src/Microsoft.AspNetCore.Authentication.Twitter/Microsoft.AspNetCore.Authentication.Twitter.csproj b/src/Microsoft.AspNetCore.Authentication.Twitter/Microsoft.AspNetCore.Authentication.Twitter.csproj index b78de6597f..6bf4a66d3f 100644 --- a/src/Microsoft.AspNetCore.Authentication.Twitter/Microsoft.AspNetCore.Authentication.Twitter.csproj +++ b/src/Microsoft.AspNetCore.Authentication.Twitter/Microsoft.AspNetCore.Authentication.Twitter.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs index dac9ee3512..d8b78398fc 100644 --- a/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs @@ -3,10 +3,8 @@ using System; using Microsoft.AspNetCore.Authentication.Twitter; -using Microsoft.AspNetCore.Authentication.Twitter.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.Extensions.DependencyInjection { @@ -21,7 +19,6 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) { services.TryAddEnumerable(ServiceDescriptor.Singleton, TwitterPostConfigureOptions>()); - services.AddSingleton, TwitterConfigureOptions>(); return services.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); } } diff --git a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs index 657c957bfb..b463ef8911 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs @@ -20,7 +20,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Newtonsoft.Json; using Xunit; @@ -40,68 +39,6 @@ namespace Microsoft.AspNetCore.Authentication.Facebook Assert.Equal(FacebookDefaults.AuthenticationScheme, scheme.DisplayName); } - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AppId", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AppSecret", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AuthorizationEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:BackchannelTimeout", "0.0:0:30"}, - //{"Facebook:CallbackPath", "/callbackpath"}, // PathString doesn't convert - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:ClaimsIssuer", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:RemoteAuthenticationTimeout", "0.0:0:30"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:SaveTokens", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:SendAppSecretProof", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:SignInScheme", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:TokenEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Facebook:UserInformationEndpoint", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddFacebookAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(FacebookDefaults.AuthenticationScheme); - Assert.Equal("", options.AppId); - Assert.Equal("", options.AppSecret); - Assert.Equal("", options.AuthorizationEndpoint); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout); - //Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert - Assert.Equal("", options.ClaimsIssuer); - Assert.Equal("", options.ClientId); - Assert.Equal("", options.ClientSecret); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout); - Assert.True(options.SaveTokens); - Assert.True(options.SendAppSecretProof); - Assert.Equal("", options.SignInScheme); - Assert.Equal("", options.TokenEndpoint); - Assert.Equal("", options.UserInformationEndpoint); - } - - [Fact] - public void AddWithDelegateIgnoresConfig() - { - var dic = new Dictionary - { - {"Facebook:AppId", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection().AddFacebookAuthentication(o => o.SaveTokens = false).AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(FacebookDefaults.AuthenticationScheme); - Assert.Null(options.AppId); - Assert.False(options.SaveTokens); - } - [Fact] public async Task ThrowsIfAppIdMissing() { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs index b316e62751..501fdf6035 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs @@ -19,7 +19,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Newtonsoft.Json; using Xunit; @@ -39,65 +38,6 @@ namespace Microsoft.AspNetCore.Authentication.Google Assert.Equal(GoogleDefaults.AuthenticationScheme, scheme.DisplayName); } - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Google:ClientId", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:ClientSecret", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:AuthorizationEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:BackchannelTimeout", "0.0:0:30"}, - //{"Google:CallbackPath", "/callbackpath"}, // PathString doesn't convert - {"Microsoft:AspNetCore:Authentication:Schemes:Google:ClaimsIssuer", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:RemoteAuthenticationTimeout", "0.0:0:30"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:SaveTokens", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:SendAppSecretProof", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:SignInScheme", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:TokenEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Google:UserInformationEndpoint", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddGoogleAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(GoogleDefaults.AuthenticationScheme); - Assert.Equal("", options.AuthorizationEndpoint); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout); - //Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert - Assert.Equal("", options.ClaimsIssuer); - Assert.Equal("", options.ClientId); - Assert.Equal("", options.ClientSecret); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout); - Assert.True(options.SaveTokens); - Assert.Equal("", options.SignInScheme); - Assert.Equal("", options.TokenEndpoint); - Assert.Equal("", options.UserInformationEndpoint); - } - - [Fact] - public void AddWithDelegateIgnoresConfig() - { - var dic = new Dictionary - { - {"Google:ClientId", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection().AddGoogleAuthentication(o => o.SaveTokens = false).AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(GoogleDefaults.AuthenticationScheme); - Assert.Null(options.ClientId); - Assert.False(options.SaveTokens); - } - [Fact] public async Task ChallengeWillTriggerRedirection() { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs index 6746f5c3f1..3149e9875b 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Microsoft.IdentityModel.Tokens; using Xunit; @@ -39,67 +38,6 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer Assert.Null(scheme.DisplayName); } - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Audience", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Authority", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:BackchannelTimeout", "0.0:0:30"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Challenge", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:ClaimsIssuer", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:IncludeErrorDetails", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:MetadataAddress", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:RefreshOnIssuerKeyNotFound", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:RequireHttpsMetadata", "false"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:SaveToken", "true"}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddJwtBearerAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(JwtBearerDefaults.AuthenticationScheme); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout); - Assert.Equal("", options.Audience); - Assert.Equal("", options.Authority); - Assert.Equal("", options.Challenge); - Assert.Equal("", options.ClaimsIssuer); - Assert.True(options.IncludeErrorDetails); - Assert.Equal("", options.MetadataAddress); - Assert.True(options.RefreshOnIssuerKeyNotFound); - Assert.False(options.RequireHttpsMetadata); - Assert.True(options.SaveToken); - } - - [Fact] - public void AddWithDelegateOverridesConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Audience", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Authority", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Bearer:RequireHttpsMetadata", "false"} - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddJwtBearerAuthentication(o => o.Authority = "authority") - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(JwtBearerDefaults.AuthenticationScheme); - Assert.Equal("", options.Audience); - Assert.Equal("authority", options.Authority); - } - [ConditionalFact(Skip = "Need to remove dependency on AAD since the generated tokens will expire")] [FrameworkSkipCondition(RuntimeFrameworks.Mono)] // https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/179 diff --git a/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs index 0d49052f5b..bf15c91b00 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs @@ -20,7 +20,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Newtonsoft.Json; using Xunit; @@ -40,65 +39,6 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount Assert.Equal(MicrosoftAccountDefaults.AuthenticationScheme, scheme.DisplayName); } - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClientId", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClientSecret", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:AuthorizationEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:BackchannelTimeout", "0.0:0:30"}, - //{"Microsoft:CallbackPath", "/callbackpath"}, // PathString doesn't convert - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClaimsIssuer", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:RemoteAuthenticationTimeout", "0.0:0:30"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:SaveTokens", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:SendAppSecretProof", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:SignInScheme", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:TokenEndpoint", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:UserInformationEndpoint", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddMicrosoftAccountAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(MicrosoftAccountDefaults.AuthenticationScheme); - Assert.Equal("", options.AuthorizationEndpoint); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout); - //Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert - Assert.Equal("", options.ClaimsIssuer); - Assert.Equal("", options.ClientId); - Assert.Equal("", options.ClientSecret); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout); - Assert.True(options.SaveTokens); - Assert.Equal("", options.SignInScheme); - Assert.Equal("", options.TokenEndpoint); - Assert.Equal("", options.UserInformationEndpoint); - } - - [Fact] - public void AddWithDelegateIgnoresConfig() - { - var dic = new Dictionary - { - {"Microsoft:ClientId", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection().AddMicrosoftAccountAuthentication(o => o.SaveTokens = true).AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(MicrosoftAccountDefaults.AuthenticationScheme); - Assert.Null(options.ClientId); - Assert.True(options.SaveTokens); - } - [Fact] public async Task ChallengeWillTriggerApplyRedirectEvent() { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/OpenIdConnectTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/OpenIdConnectTests.cs index 9dc597b856..1708e604ef 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/OpenIdConnectTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/OpenIdConnectTests.cs @@ -15,7 +15,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Xunit; @@ -30,33 +29,6 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect const string Signin = "/signin"; const string Signout = "/signout"; - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:ClientId", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:ClientSecret", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:RequireHttpsMetadata", "false"}, - {"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:Authority", ""} - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddOpenIdConnectAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(OpenIdConnectDefaults.AuthenticationScheme); - Assert.Equal("", options.ClientId); - Assert.Equal("", options.ClientSecret); - Assert.Equal("", options.Authority); - Assert.False(options.RequireHttpsMetadata); - } - - /// /// Tests RedirectForSignOutContext replaces the OpenIdConnectMesssage correctly. /// summary> diff --git a/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs index b8af66cdfb..8fcc0780d2 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Authentication.Twitter @@ -33,59 +32,6 @@ namespace Microsoft.AspNetCore.Authentication.Twitter Assert.Equal(TwitterDefaults.AuthenticationScheme, scheme.DisplayName); } - [Fact] - public void AddCanBindAgainstDefaultConfig() - { - var dic = new Dictionary - { - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ConsumerKey", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ConsumerSecret", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:BackchannelTimeout", "0.0:0:30"}, - //{"Twitter:CallbackPath", "/callbackpath"}, // PathString doesn't convert - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ClaimsIssuer", ""}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:RemoteAuthenticationTimeout", "0.0:0:30"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:SaveTokens", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:SendAppSecretProof", "true"}, - {"Microsoft:AspNetCore:Authentication:Schemes:Twitter:SignInScheme", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection() - .AddSingleton, ConfigureDefaults>() - .AddTwitterAuthentication() - .AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(TwitterDefaults.AuthenticationScheme); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout); - //Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert - Assert.Equal("", options.ClaimsIssuer); - Assert.Equal("", options.ConsumerKey); - Assert.Equal("", options.ConsumerSecret); - Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout); - Assert.True(options.SaveTokens); - Assert.Equal("", options.SignInScheme); - } - - [Fact] - public void AddWithDelegateIgnoresConfig() - { - var dic = new Dictionary - { - {"Twitter:ConsumerKey", ""}, - }; - var configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddInMemoryCollection(dic); - var config = configurationBuilder.Build(); - var services = new ServiceCollection().AddTwitterAuthentication(o => o.SaveTokens = true).AddSingleton(config); - var sp = services.BuildServiceProvider(); - - var options = sp.GetRequiredService>().Get(TwitterDefaults.AuthenticationScheme); - Assert.Null(options.ConsumerKey); - Assert.True(options.SaveTokens); - } - [Fact] public async Task ChallengeWillTriggerApplyRedirectEvent() {