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
693 stars 91 forks source link

[SCIM] publish to masstransit fails #554

Closed danflomin closed 11 months ago

danflomin commented 1 year ago

Hello, how are you?

I'm having issues with publishing events related to data with nested groups.

I'm getting the following error when trying to publish the event.

A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.Message.Attribute.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.FlatAttributes.Representation.ExternalId.

Do you think you know what the root cause of this? It was introduced when I upgraded from 2.0.25 to 4.0.2.

Kind regards Dan

simpleidserver commented 1 year ago

Hello :)

I believe you received this exception because the SCIMRepresentation object is being passed as a parameter to MassTransit, and it is not possible to serialize this object due to the presence of a reference to the Parent in the SCIMRepresentationAttribute attribute.

In the SCIM Server implementation, the SCIMRepresentation is not directly passed to MassTransit. Instead, it is serialized into JSON using the following code before being passed to MassTransit:

var content = newRepresentation.ToResponse(location, false);

Could you please check if you can serialize the Representation before passing the result to MassTransit?

KR,

SID

danflomin commented 1 year ago

Hello

I'm sorry for the incomplete information.

The exception was of type System.Runtime.Serialization.SerializationException

System.Runtime.Serialization.SerializationException: Failed to serialize message
  File "/_/src/MassTransit/Serialization/SystemTextJsonMessageBody.cs", line 56, col 17, in byte[] SystemTextJsonMessageBody<TMessage>.GetBytes()
  File "/_/src/MassTransit/InMemoryTransport/InMemoryTransport/InMemorySendTransportContext.cs", line 58, col 13, in Task InMemorySendTransportContext.Send<T>(PipeContext transportContext, SendContext<T> sendContext)
  ?, in async Task SendPipe<T>.Send(TContext context)

Kind regards Dan

simpleidserver commented 1 year ago

Thank you for raising the exception, but it should not occur in the SCIM Server. This is because the SCIMRepresentation is directly passed to MassTransit, but before sending it to MassTransit, it is first serialized into JSON.

Have you added custom code that sends the SCIMRepresentation instead of the JSON object?

Please refer to my previous message for more information :)

danflomin commented 1 year ago

No I did not :( I wonder if it happens due to a corruption in the data (maybe a circular memberships of groups?).

I guess that prior to publishing the event, it will be preferable to not add the representation that is attached to the attribute as well (it happens only for reference events).

WDYT?

danflomin commented 1 year ago

Also, can you please add my account as a contributor? I'd like to submit a pull request

simpleidserver commented 1 year ago

Oops, my bad !

The exception is being thrown because the SCIMRepresentationAttribute is passed as a parameter into the events RepresentationRefAttributeAddedEvent, RepresentationRefAttributeRemovedEvent, and RepresentationRefAttributeUpdatedEvent. Consequently, an infinite loop occurs between SCIMRepresentationAttribute and SCIMRepresentation.

I will ignore the Representation attached to the SCIMRepresentationAttribute :)

I have sent you an invitation to become a collaborator

simpleidserver commented 1 year ago

The issue should be fixed in the branch release/4.0.2

Changeset : https://github.com/simpleidserver/SimpleIdServer/commit/1419d769386b8e42ad1b120f7b7352fbd4292986

danflomin commented 12 months ago

Thank you very much!

On Tue, Jul 25, 2023, 22:18 SimpleIdServer @.***> wrote:

The issue should be fixed in the branch release/4.0.2

Changeset : 1419d76 https://github.com/simpleidserver/SimpleIdServer/commit/1419d769386b8e42ad1b120f7b7352fbd4292986

— Reply to this email directly, view it on GitHub https://github.com/simpleidserver/SimpleIdServer/issues/554#issuecomment-1650398806, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIB5S7MMSAWQGVIG3IMN633XSALYNANCNFSM6AAAAAA2VIFUE4 . You are receiving this because you authored the thread.Message ID: @.***>

danflomin commented 12 months ago

Hello

I pushed an improvement to release/4.0.2. I need this for my application.

Is that OK?

Kind regards Dan

simpleidserver commented 12 months ago

Hello,

Sorry for my late reply, i'm ok with your changes :)

KR,

SID