okta / okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Other
159 stars 100 forks source link

Make client serializer public #714

Open gao-artur opened 6 months ago

gao-artur commented 6 months ago

Describe the bug?

This should be a feature request rather than a bug, but the feature request form doesn't seem to fit, in my opinion. I'm migrating Okta.SDK from v5.4.1 to v7.0.6. Previously, after receiving the Hook Event I used this code to deserialize it into ILogEvent objects:

private IEnumerable<ILogEvent> DeserializeEvents(JArray events)
{
    var data = new DefaultSerializer().DeserializeArray(events.ToString());
    var factory = new ResourceFactory(_oktaClient, _logger);
    return data.Select(e => factory.CreateNew<LogEvent>(e));
}

Unfortunately, since v6 it's not possible anymore. Looking into the source code, I found that the serializer is now configured on the RestSharp client and it's not accessible from the outside https://github.com/okta/okta-sdk-dotnet/blob/b95064cd549113880db10c8629be822628e0c7ea/src/Okta.Sdk/Client/ApiClient.cs#L497

I'd like to request making the serializer public and not coupled to the RestSharp.

What is expected to happen?

I should be able to deserialize the Okta hook events into Okta.Sdk.Model.LogEvent using the SDK's serializer.

What is the actual behavior?

The serializer is internal and not accessible from the user code.

Reproduction Steps?

Subscribe to event hook. Deserialize the received json into the following (simplified) structure

public class EventPayload
{
    public Data Data { get; set; }
}

public class Data
{
    public JArray Events { get; set; }
}

Try deserializing the EventPayload.Data.Events to IEnumerable<Okta.Sdk.Model.LogEvent>

Additional Information?

No response

.NET Version

8.0.204

SDK Version

7.0.6

OS version

No response

gao-artur commented 6 months ago

Looking closer, the important part is SerializerSettings and handling nullable types.

bryanapellanes-okta commented 5 months ago

@gao-artur Thanks for your request. I've added an internal issue for tracking and prioritization. OKTA-730149