msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Switch From Using Unmaintained Newtonsoft.Json to Using System.Text.Json in Powershell Authentication Module

Open fey101 opened this issue 1 year ago • 1 comments

Describe the bug

The Newtonsoft.Json dependency of the SDK's authentication module, is no longer actively maintained. In the past we have also encountered trust issues with the signed Newtonsoft.Json package throwing verificationError 18 which interprets to "Your file is signed but we don't trust it" and PS SDK users, have raised this too as an issue for them. See https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2741 and https://github.com/JamesNK/Newtonsoft.Json/issues/2755

Expected behavior

Avoid Newtonsoft.Json related issues mentioned above by switching to System.Text.Json

How to reproduce

The task will include writing tests to cover the affected code segments and mitigate against any regressions before switching to system.text.json.

The current tricky work is the Json DOM handling in the 3 files below

  • https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/Authentication/Authentication/Common/GraphSettings.cs
  • https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/Authentication/Authentication/Common/GraphSettingsConverter.cs
  • https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/Authentication/Authentication/Helpers/StringUtil.cs

It should be easier to replace JsonConvert.SerializeObject with JsonSerializer.Seralize in other files like https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/f06dcb11f2064bcd73ba3393dc9523c9bd45235f/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs#L579

Acceptance Criteria

  • 100% test coverage on affected files/files originally using Newtonsoft.Json package
  • Working authentication module with the tests passing and using System.Text.Json instead of Newtonsoft.Json

fey101 avatar Jun 04 '24 07:06 fey101

We also need to bump System.Text.Json that has a CVE & is causing conflicts with ExchangeOnlineManagement

Ndiritu avatar Jan 08 '25 13:01 Ndiritu