PowerDMS / Owin.Scim

OWIN SCIM 1.1 & 2.0 implementation for .NET
MIT License
63 stars 29 forks source link

Asp.net webapi error message #46

Open ghost opened 6 years ago

ghost commented 6 years ago

I have followed the WIKI trying to create a ASP.NET Web Api project with Owin.Scim. Once running on localhost, the only endpoint that ASP.NET can discover is v2/resourcetypes. When trying to access this endpoint, i recieve the following error; `

An error has occurred. An error occurred when trying to create a controller of type 'ResourceTypesController'. Make sure that the controller has a parameterless public constructor. System.InvalidOperationException ved System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) ved System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) ved System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext() An error has occurred. Typen 'Owin.Scim.v2.Endpoints.ResourceTypesController' har ikke en standardkonstruktør System.ArgumentException ved System.Linq.Expressions.Expression.New(Type type) ved System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) ved System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) ved System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)

`

All of the other endpoints (v2/Users, etc.) returns 404.

My Startup.cs looks like this; ` var config = new HttpConfiguration();

        config.Routes.MapHttpRoute(
            "DefaultApi",
            "api/{controller}/{id}",
            new { id = RouteParameter.Optional });

        var builder = new ContainerBuilder();
        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
        builder.RegisterType<UserRepository>().AsSelf();
        builder.RegisterType<GroupRepository>().AsSelf();

        var container = builder.Build();
        config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

        appBuilder.UseAutofacMiddleware(container);

        appBuilder.Map("/scim", app =>
        {
            app.UseScimServer(new Predicate<FileInfo>[] {fileInfo => fileInfo.Name.Equals("MyScimProject")},
                configuration =>
                {
                    configuration.RequireSsl = false; // disable SSL requirements
                    configuration.EnableEndpointAuthorization = false; // disable authentication requirements
                    configuration.DependencyResolver = new FuncDependencyResolver(type => container.Resolve(type));
                });
        });

        appBuilder.UseAutofacWebApi(config);
        appBuilder.UseWebApi(config);`
amd989 commented 6 years ago

You should try append /scim at the beginning of your requests. i.e: /scim/v2/XXXX

I'm getting the same issue. In this case is with the UsersController as well, when I do /scim/v2/users

{"schemas":["urn:ietf:params:scim:api:messages:2.0:Error"],"status":"500","scimType":null,"detail":"System.InvalidOperationException: An error occurred when trying to create a controller of type 'UsersController'. Make sure that the controller has a parameterless public constructor. ---> System.ArgumentException: Type 'Owin.Scim.v2.Endpoints.UsersController' does not have a default constructor   
at System.Linq.Expressions.Expression.New(Type type)
   at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
  at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
   --- End of inner exception stack trace ---\r\n   at

It happens with new implementation as well as the sample projects. Tried different nuget packages but all seem to have the same issue... Not sure why the internal IoC won't resolve the scim controllers.