[Bug] The JSON value could not be converted to System.Int64. ROPC flow
See original GitHub issueLogs and network traces
System.Text.Json.JsonException
The JSON value could not be converted to System.Int64. Path: $.expires_in | LineNumber: 0 | BytePositionInLine: 1332.
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerContext context)
at Microsoft.Identity.Client.Utils.JsonHelper.DeserializeFromJson[T](String json)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders, Func`2 onBeforePostRequestData)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.GetTokenAsync(Uri endPoint, RequestContext requestContext, Boolean addCommonHeaders, Func`2 onBeforePostRequestHandler)
at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint, ILoggerAdapter logger)
at Microsoft.Identity.Client.OAuth2.TokenClient.SendTokenRequestAsync(IDictionary`2 additionalBodyParameters, String scopeOverride, String tokenEndpointOverride, CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.GetTokenResponseAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.ExecuteAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenByUsernamePasswordParameters usernamePasswordParameters, CancellationToken cancellationToken)
Which version of MSAL.NET are you using? MSAL.NET 4.49.x, 4.48.x - Problem Works in 4.47.2 - No Issues
Platform .Net 7.0, .Net 6.0 (.Net 4.8 not tested)
What authentication flow has the issue?
- Desktop / Mobile
- Interactive
- Integrated Windows Authentication
- Username Password
- Device code flow (browserless)
- Web app
- Authorization code
- On-Behalf-Of
- Daemon app
- Service to Service calls
Other?
Is this a new or existing app? a. The app is in production, and I have upgraded to a new version of MSAL. –>
Repro
var publicClientBuilder = PublicClientApplicationBuilder.CreateWithApplicationOptions(options);
publicClientBuilder.WithB2CAuthority('MY AUTHORITY');
var publicClient = publicClientBuilder.Build();
// Gives exception only after upgrade to 4.48+
var result = await publicClient.AcquireTokenByUsernamePassword(
new string[]{'MyScopes1', 'MyScope2'},
'MyUserName',
password)
.ExecuteAsync().ConfigureAwait(false);
Some guess about the issue:
Probably something went wrong when STJ deseriailzer Source Generator ignored the settings that are defined here:
Azure AD B2C returns expires_in field as a string 😦 https://learn.microsoft.com/en-us/answers/questions/877384/azure-active-directory-b2c-authorization-code-flow.html
Issue Analytics
- State:
- Created 8 months ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top Results From Across the Web
The JSON value could not be converted to System.Int64
You do not need to call JSON.Stringify. Expand your TypeScript model to export class Order { orderId: number orderNo: string customerId: ...
Read more >JsonSerializer.Deserialize(... JsonSerializerContext context ...
[Bug] The JSON value could not be converted to System.Int64. ROPC flow AzureAD/microsoft-authentication-library-for-dotnet#3892.
Read more >The JSON value could not be converted to System. ...
Hi, I am trying to read OneSignal REST's Json but getting below error: The JSON value could not be converted to System.Collections.Generic.
Read more >Fixing JSON parsing exception "value could not be ...
Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.value[0].fields['System.
Read more >The JSON value could not be converted to System.String. ...
String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073. Error.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
opened bug on .NET 7 repo https://github.com/dotnet/runtime/issues/80634
I can confirm with my testing that targeting .NET 7 causes this issue. Targeting .NET 6 seems to resolve it with the latest version of MSAL so targeting 6.0.7 seems to be a temporary work around