Merge branch 'rel/2.0.0-preview2' into dev

This commit is contained in:
Hao Kung 2017-06-05 11:34:49 -07:00
commit 6d4fa4e91c
24 changed files with 3 additions and 460 deletions

View File

@ -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<FacebookOptions> configureOptions)
{
services.AddSingleton<ConfigureDefaultOptions<FacebookOptions>, FacebookConfigureOptions>();
return services.AddOAuthAuthentication<FacebookOptions, FacebookHandler>(authenticationScheme, configureOptions);
}
=> services.AddOAuthAuthentication<FacebookOptions, FacebookHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -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<FacebookOptions>
{
public FacebookConfigureOptions(IConfiguration config) :
base(FacebookDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+FacebookDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.OAuth\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

View File

@ -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<GoogleOptions> configureOptions)
{
services.AddSingleton<ConfigureDefaultOptions<GoogleOptions>, GoogleConfigureOptions>();
return services.AddOAuthAuthentication<GoogleOptions, GoogleHandler>(authenticationScheme, configureOptions);
}
=> services.AddOAuthAuthentication<GoogleOptions, GoogleHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -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<GoogleOptions>
{
public GoogleConfigureOptions(IConfiguration config) :
base(GoogleDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+GoogleDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.OAuth\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

View File

@ -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<JwtBearerOptions>
{
// Bind to "Bearer" section by default
public JwtBearerConfigureOptions(IConfiguration config) :
base(JwtBearerDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+JwtBearerDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -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<JwtBearerOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerPostConfigureOptions>());
services.AddSingleton<ConfigureDefaultOptions<JwtBearerOptions>, JwtBearerConfigureOptions>();
return services.AddScheme<JwtBearerOptions, JwtBearerHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -11,7 +11,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication\Microsoft.AspNetCore.Authentication.csproj" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="$(IdentityModelOpenIdVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
</ItemGroup>
</Project>

View File

@ -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<MicrosoftAccountOptions>
{
// Bind to "Microsoft" section by default
public MicrosoftAccountConfigureOptions(IConfiguration config) :
base(MicrosoftAccountDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+MicrosoftAccountDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.OAuth\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

View File

@ -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<MicrosoftAccountOptions> configureOptions)
{
services.AddSingleton<ConfigureDefaultOptions<MicrosoftAccountOptions>, MicrosoftAccountConfigureOptions>();
return services.AddOAuthAuthentication<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, configureOptions);
}
=> services.AddOAuthAuthentication<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -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<OpenIdConnectOptions>
{
// Bind to "OpenIdConnect" section by default
public OpenIdConnectConfigureOptions(IConfiguration config) :
base(OpenIdConnectDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+OpenIdConnectDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -12,6 +12,5 @@
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.OAuth\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="$(IdentityModelOpenIdVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

View File

@ -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<OpenIdConnectOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>());
services.AddSingleton<ConfigureDefaultOptions<OpenIdConnectOptions>, OpenIdConnectConfigureOptions>();
return services.AddRemoteScheme<OpenIdConnectOptions, OpenIdConnectHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
}

View File

@ -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<TwitterOptions>
{
// Bind to "Twitter" section by default
public TwitterConfigureOptions(IConfiguration config) :
base(TwitterDefaults.AuthenticationScheme,
options => config.GetSection("Microsoft:AspNetCore:Authentication:Schemes:"+TwitterDefaults.AuthenticationScheme).Bind(options))
{ }
}
}

View File

@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication.OAuth\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
</ItemGroup>

View File

@ -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<TwitterOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TwitterOptions>, TwitterPostConfigureOptions>());
services.AddSingleton<ConfigureDefaultOptions<TwitterOptions>, TwitterConfigureOptions>();
return services.AddRemoteScheme<TwitterOptions, TwitterHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
}

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AppId", "<id>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AppSecret", "<secret>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:AuthorizationEndpoint", "<authEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:BackchannelTimeout", "0.0:0:30"},
//{"Facebook:CallbackPath", "/callbackpath"}, // PathString doesn't convert
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:ClaimsIssuer", "<issuer>"},
{"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", "<signIn>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:TokenEndpoint", "<tokenEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Facebook:UserInformationEndpoint", "<userEndpoint>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<FacebookOptions>, ConfigureDefaults<FacebookOptions>>()
.AddFacebookAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<FacebookOptions>>().Get(FacebookDefaults.AuthenticationScheme);
Assert.Equal("<id>", options.AppId);
Assert.Equal("<secret>", options.AppSecret);
Assert.Equal("<authEndpoint>", options.AuthorizationEndpoint);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout);
//Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert
Assert.Equal("<issuer>", options.ClaimsIssuer);
Assert.Equal("<id>", options.ClientId);
Assert.Equal("<secret>", options.ClientSecret);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout);
Assert.True(options.SaveTokens);
Assert.True(options.SendAppSecretProof);
Assert.Equal("<signIn>", options.SignInScheme);
Assert.Equal("<tokenEndpoint>", options.TokenEndpoint);
Assert.Equal("<userEndpoint>", options.UserInformationEndpoint);
}
[Fact]
public void AddWithDelegateIgnoresConfig()
{
var dic = new Dictionary<string, string>
{
{"Facebook:AppId", "<id>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection().AddFacebookAuthentication(o => o.SaveTokens = false).AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<FacebookOptions>>().Get(FacebookDefaults.AuthenticationScheme);
Assert.Null(options.AppId);
Assert.False(options.SaveTokens);
}
[Fact]
public async Task ThrowsIfAppIdMissing()
{

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Google:ClientId", "<id>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Google:ClientSecret", "<secret>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Google:AuthorizationEndpoint", "<authEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Google:BackchannelTimeout", "0.0:0:30"},
//{"Google:CallbackPath", "/callbackpath"}, // PathString doesn't convert
{"Microsoft:AspNetCore:Authentication:Schemes:Google:ClaimsIssuer", "<issuer>"},
{"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", "<signIn>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Google:TokenEndpoint", "<tokenEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Google:UserInformationEndpoint", "<userEndpoint>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<GoogleOptions>, ConfigureDefaults<GoogleOptions>>()
.AddGoogleAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<GoogleOptions>>().Get(GoogleDefaults.AuthenticationScheme);
Assert.Equal("<authEndpoint>", options.AuthorizationEndpoint);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout);
//Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert
Assert.Equal("<issuer>", options.ClaimsIssuer);
Assert.Equal("<id>", options.ClientId);
Assert.Equal("<secret>", options.ClientSecret);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout);
Assert.True(options.SaveTokens);
Assert.Equal("<signIn>", options.SignInScheme);
Assert.Equal("<tokenEndpoint>", options.TokenEndpoint);
Assert.Equal("<userEndpoint>", options.UserInformationEndpoint);
}
[Fact]
public void AddWithDelegateIgnoresConfig()
{
var dic = new Dictionary<string, string>
{
{"Google:ClientId", "<id>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection().AddGoogleAuthentication(o => o.SaveTokens = false).AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<GoogleOptions>>().Get(GoogleDefaults.AuthenticationScheme);
Assert.Null(options.ClientId);
Assert.False(options.SaveTokens);
}
[Fact]
public async Task ChallengeWillTriggerRedirection()
{

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Audience", "<audience>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Authority", "<authority>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:BackchannelTimeout", "0.0:0:30"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Challenge", "<challenge>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:ClaimsIssuer", "<issuer>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:IncludeErrorDetails", "true"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:MetadataAddress", "<metadata>"},
{"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<IConfigureOptions<JwtBearerOptions>, ConfigureDefaults<JwtBearerOptions>>()
.AddJwtBearerAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get(JwtBearerDefaults.AuthenticationScheme);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout);
Assert.Equal("<audience>", options.Audience);
Assert.Equal("<authority>", options.Authority);
Assert.Equal("<challenge>", options.Challenge);
Assert.Equal("<issuer>", options.ClaimsIssuer);
Assert.True(options.IncludeErrorDetails);
Assert.Equal("<metadata>", options.MetadataAddress);
Assert.True(options.RefreshOnIssuerKeyNotFound);
Assert.False(options.RequireHttpsMetadata);
Assert.True(options.SaveToken);
}
[Fact]
public void AddWithDelegateOverridesConfig()
{
var dic = new Dictionary<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Audience", "<audience>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:Authority", "<authority>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Bearer:RequireHttpsMetadata", "false"}
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<JwtBearerOptions>, ConfigureDefaults<JwtBearerOptions>>()
.AddJwtBearerAuthentication(o => o.Authority = "authority")
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get(JwtBearerDefaults.AuthenticationScheme);
Assert.Equal("<audience>", 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

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClientId", "<id>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClientSecret", "<secret>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:AuthorizationEndpoint", "<authEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:BackchannelTimeout", "0.0:0:30"},
//{"Microsoft:CallbackPath", "/callbackpath"}, // PathString doesn't convert
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:ClaimsIssuer", "<issuer>"},
{"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", "<signIn>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:TokenEndpoint", "<tokenEndpoint>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Microsoft:UserInformationEndpoint", "<userEndpoint>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<MicrosoftAccountOptions>, ConfigureDefaults<MicrosoftAccountOptions>>()
.AddMicrosoftAccountAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<MicrosoftAccountOptions>>().Get(MicrosoftAccountDefaults.AuthenticationScheme);
Assert.Equal("<authEndpoint>", options.AuthorizationEndpoint);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.BackchannelTimeout);
//Assert.Equal("/callbackpath", options.CallbackPath); // NOTE: PathString doesn't convert
Assert.Equal("<issuer>", options.ClaimsIssuer);
Assert.Equal("<id>", options.ClientId);
Assert.Equal("<secret>", options.ClientSecret);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout);
Assert.True(options.SaveTokens);
Assert.Equal("<signIn>", options.SignInScheme);
Assert.Equal("<tokenEndpoint>", options.TokenEndpoint);
Assert.Equal("<userEndpoint>", options.UserInformationEndpoint);
}
[Fact]
public void AddWithDelegateIgnoresConfig()
{
var dic = new Dictionary<string, string>
{
{"Microsoft:ClientId", "<id>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection().AddMicrosoftAccountAuthentication(o => o.SaveTokens = true).AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<MicrosoftAccountOptions>>().Get(MicrosoftAccountDefaults.AuthenticationScheme);
Assert.Null(options.ClientId);
Assert.True(options.SaveTokens);
}
[Fact]
public async Task ChallengeWillTriggerApplyRedirectEvent()
{

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:ClientId", "<id>"},
{"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:ClientSecret", "<secret>"},
{"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:RequireHttpsMetadata", "false"},
{"Microsoft:AspNetCore:Authentication:Schemes:OpenIdConnect:Authority", "<auth>"}
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, ConfigureDefaults<OpenIdConnectOptions>>()
.AddOpenIdConnectAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<OpenIdConnectOptions>>().Get(OpenIdConnectDefaults.AuthenticationScheme);
Assert.Equal("<id>", options.ClientId);
Assert.Equal("<secret>", options.ClientSecret);
Assert.Equal("<auth>", options.Authority);
Assert.False(options.RequireHttpsMetadata);
}
/// <summary>
/// Tests RedirectForSignOutContext replaces the OpenIdConnectMesssage correctly.
/// summary>

View File

@ -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<string, string>
{
{"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ConsumerKey", "<key>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ConsumerSecret", "<secret>"},
{"Microsoft:AspNetCore:Authentication:Schemes:Twitter:BackchannelTimeout", "0.0:0:30"},
//{"Twitter:CallbackPath", "/callbackpath"}, // PathString doesn't convert
{"Microsoft:AspNetCore:Authentication:Schemes:Twitter:ClaimsIssuer", "<issuer>"},
{"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", "<signIn>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection()
.AddSingleton<IConfigureOptions<TwitterOptions>, ConfigureDefaults<TwitterOptions>>()
.AddTwitterAuthentication()
.AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<TwitterOptions>>().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("<issuer>", options.ClaimsIssuer);
Assert.Equal("<key>", options.ConsumerKey);
Assert.Equal("<secret>", options.ConsumerSecret);
Assert.Equal(new TimeSpan(0, 0, 0, 30), options.RemoteAuthenticationTimeout);
Assert.True(options.SaveTokens);
Assert.Equal("<signIn>", options.SignInScheme);
}
[Fact]
public void AddWithDelegateIgnoresConfig()
{
var dic = new Dictionary<string, string>
{
{"Twitter:ConsumerKey", "<key>"},
};
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(dic);
var config = configurationBuilder.Build();
var services = new ServiceCollection().AddTwitterAuthentication(o => o.SaveTokens = true).AddSingleton<IConfiguration>(config);
var sp = services.BuildServiceProvider();
var options = sp.GetRequiredService<IOptionsSnapshot<TwitterOptions>>().Get(TwitterDefaults.AuthenticationScheme);
Assert.Null(options.ConsumerKey);
Assert.True(options.SaveTokens);
}
[Fact]
public async Task ChallengeWillTriggerApplyRedirectEvent()
{