simpleidserver / SimpleIdServer

OpenID, OAuth 2.0, SCIM2.0, UMA2.0, FAPI, CIBA & OPENBANKING Framework for ASP.NET Core
https://simpleidserver.com/
Apache License 2.0
682 stars 90 forks source link

SCIM POST /Bulk Error 500: System.InvalidOperationException: Feature 'Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature' is not present #720

Closed LazaroOnline closed 3 months ago

LazaroOnline commented 3 months ago

SCIM POST /Bulk operation is throwing an exception: System.InvalidOperationException: Feature 'Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature' is not present

POST /Bulk Example body:

{
  "schemas": [
    "urn:ietf:params:scim:api:messages:2.0:BulkRequest"
  ],
  "operations": [
    {
      "method": "POST",
      "path": "/Users",
      "bulkId": "user0",
      "data": {
        "userName": "user-0-username-995b6946-70a4-49b3-9363-5079d5198387",
        "active": true,
        "schemas": [
          "urn:ietf:params:scim:schemas:core:2.0:User"
        ],
        "name": {
          "familyName": "user-0-familyName",
          "givenName": "user-0-givenName"
        },
        "emails": [
          {
            "primary": true,
            "type": "work",
            "value": "user-995b6946-70a4-49b3-9363-5079d5198387@company.com"
          }
        ]
      }
    },
    {
      "method": "POST",
      "path": "/Users",
      "bulkId": "user1",
      "data": {
        "userName": "user-1-username-4dfdf8f5-7d87-42a5-87a0-4b3c4f8f81a0",
        "active": true,
        "schemas": [
          "urn:ietf:params:scim:schemas:core:2.0:User"
        ],
        "name": {
          "familyName": "user-1-familyName",
          "givenName": "user-1-givenName"
        },
        "emails": [
          {
            "primary": true,
            "type": "work",
            "value": "user-4dfdf8f5-7d87-42a5-87a0-4b3c4f8f81a0@company.com"
          }
        ]
      }
    }
  ]
}

SimpleIdServer\src\Scim\SimpleIdServer.Scim\Api\BulkController.cs

using (var scope = _serviceScopeFactory.CreateScope())
{
    newHttpContext.RequestServices = scope.ServiceProvider;
    newHttpContext.Response.Body = new MemoryStream();

EXCEPTION: System.InvalidOperationException: Feature 'Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature' is not present. at Microsoft.AspNetCore.Http.Features.FeatureCollectionExtensions.GetRequiredFeature[TFeature](IFeatureCollection featureCollection) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_Body(Stream value) at SimpleIdServer.Scim.Api.BulkController.ExecuteBulkOperation(BulkOperationParameter scimBulkOperationRequest) at SimpleIdServer.Scim.Api.BulkController.Index(BulkParameter bulk)

Tested in the current latest of "SimpleIdServer.Scim" v4.0.7

simpleidserver commented 3 months ago

This exception is thrown due to a breaking change in the latest version of Microsoft.AspNetCore, rendering the IHttpResponseBodyFeature unusable for redirecting incoming HTTP requests to the appropriate request. Considering the future upgrade to DOTNET 8, could you please verify if your Startup.cs class resembles the one in our sample project: https://github.com/simpleidserver/SimpleIdServer/blob/master/src/Scim/SimpleIdServer.Scim.Startup/Startup.cs

LazaroOnline commented 3 months ago

I will upgrade to the SCIM version with dotnet 8 once it is released as far as I can solve any other errors/breaking changes in that version. Until then I'm trying to upgrade to v4.0.7, using dotnet 7.0.17, my startup looks very similar to the example mentioned above from this repo, I don't see any relevant difference, so I'm not sure what I'm missing.

simpleidserver commented 3 months ago

Indeed, this exception occurred because there is a mismatch between the Microsoft.AspNetCore version used by the Startup project and the SCIM library. :(

I have made some modifications in the master branch to fix this issue. I made the following changes:

Could you please check if this issue still exists by using the master branch?

LazaroOnline commented 3 months ago

Yes, it worked using dotnet 7 and the current latest commit from master "0a0540a", so I will upgrade once the new version 4.0.8 is released.

Thank you very much!