public static void IValidationKeysStore_Service_Resolution_Fails_If_No_Signing_Credential_Configured() { // Arrange IConfiguration configuration = new ConfigurationBuilder() .Build(); IWebHostEnvironment environment = new MyWebHostEnvironment(); var services = new ServiceCollection() .AddSingleton(configuration) .AddSingleton(environment) .AddOptions(); services.AddDefaultIdentity <MyUser>(); services.AddIdentityServer() .AddApiAuthorization <MyUser, MyUserContext>(); using var serviceProvider = services.BuildServiceProvider(); // Act and Assert var exception = Assert.Throws <InvalidOperationException>( () => serviceProvider.GetRequiredService <IValidationKeysStore>()); Assert.Equal("No signing credential is configured by the 'IdentityServer:Key' configuration section.", exception.Message); }
public static void IValidationKeysStore_Service_Resolution_Succeeds_If_Key_Found() { // Arrange IConfiguration configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { ["IdentityServer:Key:Type"] = "File", ["IdentityServer:Key:FilePath"] = "test.pfx", ["IdentityServer:Key:Password"] = "******" }).Build(); IWebHostEnvironment environment = new MyWebHostEnvironment(); var services = new ServiceCollection() .AddSingleton(configuration) .AddSingleton(environment) .AddOptions(); services.AddDefaultIdentity <MyUser>(); services.AddIdentityServer() .AddApiAuthorization <MyUser, MyUserContext>(); services.AddAuthentication(); using var serviceProvider = services.BuildServiceProvider(); // Act var store = serviceProvider.GetRequiredService <IValidationKeysStore>(); // Assert Assert.NotNull(store); }