public void PostConfigure_ThrowsAnExceptionWhenDefaultSchemesPointToServerHandler(string[] schemes) { // Arrange var options = new AuthenticationOptions { DefaultAuthenticateScheme = schemes[0], DefaultChallengeScheme = schemes[1], DefaultForbidScheme = schemes[2], DefaultScheme = schemes[3], DefaultSignInScheme = schemes[4], DefaultSignOutScheme = schemes[5] }; options.AddScheme <OpenIddictServerHandler>(OpenIddictServerDefaults.AuthenticationScheme, displayName: null); var configuration = new OpenIddictServerConfiguration( Mock.Of <IDistributedCache>(), Mock.Of <IDataProtectionProvider>()); // Act and assert var exception = Assert.Throws <InvalidOperationException>(() => configuration.PostConfigure(Options.DefaultName, options)); // Assert Assert.Equal(new StringBuilder() .AppendLine("The OpenIddict server handler cannot be used as the default scheme handler.") .Append("Make sure that neither DefaultAuthenticateScheme, DefaultChallengeScheme, ") .Append("DefaultForbidScheme, DefaultSignInScheme, DefaultSignOutScheme nor DefaultScheme ") .Append("point to an instance of the OpenIddict server handler.") .ToString(), exception.Message); }
public void Configure_ThrowsAnExceptionWhenSchemeIsAlreadyRegisteredWithDifferentHandlerType() { // Arrange var options = new AuthenticationOptions(); options.AddScheme(OpenIddictValidationDefaults.AuthenticationScheme, builder => { builder.HandlerType = typeof(OAuthValidationHandler); }); var initializer = new OpenIddictValidationConfiguration(Mock.Of <IDataProtectionProvider>()); // Act and assert var exception = Assert.Throws <InvalidOperationException>(() => initializer.Configure(options)); Assert.Equal(new StringBuilder() .AppendLine("The OpenIddict validation handler cannot be registered as an authentication scheme.") .AppendLine("This may indicate that an instance of the OAuth validation or JWT bearer handler was registered.") .Append("Make sure that neither 'services.AddAuthentication().AddOAuthValidation()' nor ") .Append("'services.AddAuthentication().AddJwtBearer()' are called from 'ConfigureServices'.") .ToString(), exception.Message); }
public void Configure_ThrowsAnExceptionWhenSchemeIsAlreadyRegisteredWithDifferentHandlerType() { // Arrange var options = new AuthenticationOptions(); options.AddScheme(OpenIddictServerDefaults.AuthenticationScheme, builder => { builder.HandlerType = typeof(OpenIdConnectServerHandler); }); var configuration = new OpenIddictServerConfiguration( Mock.Of <IDistributedCache>(), Mock.Of <IDataProtectionProvider>()); // Act and assert var exception = Assert.Throws <InvalidOperationException>(() => configuration.Configure(options)); Assert.Equal(new StringBuilder() .AppendLine("The OpenIddict server handler cannot be registered as an authentication scheme.") .AppendLine("This may indicate that an instance of the OpenID Connect server was registered.") .Append("Make sure that 'services.AddAuthentication().AddOpenIdConnectServer()' is not used.") .ToString(), exception.Message); }
private void ConfigureAuthentication( AuthenticationOptions options) { options.AddScheme(PolicyConstants.ApiKeyAuthenticationScheme, builder => { builder.HandlerType = typeof(ApiKeyAuthenticationHandler); }); }