Skip to content

Commit 3b867a7

Browse files
committed
Fix Android
1 parent 9007524 commit 3b867a7

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidAccountManagerBroker.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.Identity.Client.Internal.Broker;
1313
using Microsoft.Identity.Client.OAuth2;
1414
using Microsoft.Identity.Client.UI;
15-
using Microsoft.Identity.Json.Linq;
1615
using Microsoft.Identity.Client.Internal.Requests;
1716
using Microsoft.Identity.Client.ApiConfig.Parameters;
1817
using Microsoft.Identity.Client.Http;
@@ -350,14 +349,16 @@ public async Task InitiateBrokerHandshakeAsync()
350349
return;
351350
}
352351

353-
dynamic errorResult = JObject.Parse(helloRequestResult.GetString(BrokerConstants.BrokerResultV2));
352+
string errorResponse = helloRequestResult.GetString(BrokerConstants.BrokerResultV2);
354353
string errorCode = null;
355354
string errorDescription = null;
356355

357-
if (!string.IsNullOrEmpty(errorResult))
356+
if (!string.IsNullOrEmpty(errorResponse))
358357
{
359-
errorCode = errorResult[BrokerResponseConst.BrokerErrorCode]?.ToString();
360-
string errorMessage = errorResult[BrokerResponseConst.BrokerErrorMessage]?.ToString();
358+
// serialize the error response to get the error code and error message withouth dynamic
359+
var errorResult = JsonHelper.DeserializeFromJson<BrokerErrorResponse>(errorResponse);
360+
errorCode = errorResult.BrokerErrorCode;
361+
string errorMessage = errorResult.BrokerErrorMessage;
361362
errorDescription = $"[Android broker] An error occurred during hand shake with the broker. Error: {errorCode} Error Message: {errorMessage}";
362363
}
363364
else

src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidContentProviderBroker.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ public string GetProtocolKeyFromHandShakeResult(Bundle bundleResult)
7272
return negotiatedBrokerProtocalKey;
7373
}
7474

75-
// json response: {"broker_error_code":"500","broker_error_message":"Broker is not installed on the device."}
76-
77-
dynamic errorResult = JObject.Parse(bundleResult?.GetString(BrokerConstants.BrokerResultV2));
75+
string errorResponse = bundleResult.GetString(BrokerConstants.BrokerResultV2);
7876
string errorCode = null;
7977
string errorDescription = null;
8078

81-
if (!string.IsNullOrEmpty(errorResult))
79+
if (!string.IsNullOrEmpty(errorResponse))
8280
{
83-
errorCode = errorResult[BrokerResponseConst.BrokerErrorCode]?.ToString();
84-
string errorMessage = errorResult[BrokerResponseConst.BrokerErrorMessage]?.ToString();
81+
// serialize the error response to get the error code and error message withouth dynamic
82+
var errorResult = JsonHelper.DeserializeFromJson<BrokerErrorResponse>(errorResponse);
83+
errorCode = errorResult.BrokerErrorCode;
84+
string errorMessage = errorResult.BrokerErrorMessage;
8585
errorDescription = $"[Android broker] An error occurred during hand shake with the broker. Error: {errorCode} Error Message: {errorMessage}";
86-
}
86+
}
8787
else
8888
{
8989
errorCode = BrokerConstants.BrokerUnknownErrorCode;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json.Serialization;
5+
using Microsoft.Identity.Client.Internal.Broker;
6+
7+
namespace Microsoft.Identity.Client.Platforms.Android.Broker
8+
{
9+
[Preserve(AllMembers = true)]
10+
internal class BrokerErrorResponse
11+
{
12+
[JsonPropertyName(BrokerResponseConst.BrokerErrorCode)]
13+
public string BrokerErrorCode { get; set; }
14+
15+
[JsonPropertyName(BrokerResponseConst.BrokerErrorMessage)]
16+
public string BrokerErrorMessage { get; set; }
17+
}
18+
}

src/client/Microsoft.Identity.Client/Platforms/Android/Broker/BrokerRequest.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Linq;
6+
using System.Text.Json.Serialization;
67
using Android.App;
78
using Android.Content.PM;
89
using Microsoft.Identity.Client.ApiConfig.Parameters;
@@ -13,45 +14,44 @@
1314

1415
namespace Microsoft.Identity.Client.Platforms.Android.Broker
1516
{
16-
[JsonObject]
1717
[Preserve(AllMembers = true)]
1818
internal class BrokerRequest
1919
{
20-
[JsonProperty("authority")]
20+
[JsonPropertyName("authority")]
2121
public string Authority { get; set; }
22-
[JsonProperty("scopes")]
22+
[JsonPropertyName("scopes")]
2323
public string Scopes { get; set; }
24-
[JsonProperty("redirect_uri")]
24+
[JsonPropertyName("redirect_uri")]
2525
public string UrlEncodedRedirectUri
2626
{
2727
get { return GetEncodedRedirectUri(RedirectUri); }
2828
}
2929

30-
[JsonProperty("client_id")]
30+
[JsonPropertyName("client_id")]
3131
public string ClientId { get; set; }
32-
[JsonProperty("home_account_id")]
32+
[JsonPropertyName("home_account_id")]
3333
public string HomeAccountId { get; set; }
34-
[JsonProperty("local_account_id")]
34+
[JsonPropertyName("local_account_id")]
3535
public string LocalAccountId { get; set; }
36-
[JsonProperty("username")]
36+
[JsonPropertyName("username")]
3737
public string UserName { get; set; }
38-
[JsonProperty("extra_query_param")]
38+
[JsonPropertyName("extra_query_param")]
3939
public string ExtraQueryParameters { get; set; }
40-
[JsonProperty("correlation_id")]
40+
[JsonPropertyName("correlation_id")]
4141
public string CorrelationId { get; set; }
42-
[JsonProperty("prompt")]
42+
[JsonPropertyName("prompt")]
4343
public string Prompt { get; set; }
44-
[JsonProperty("claims")]
44+
[JsonPropertyName("claims")]
4545
public string Claims { get; set; }
46-
[JsonProperty("force_refresh")]
46+
[JsonPropertyName("force_refresh")]
4747
public string ForceRefresh { get; set; }
48-
[JsonProperty("client_app_name")]
48+
[JsonPropertyName("client_app_name")]
4949
public string ClientAppName { get; set; }
50-
[JsonProperty("client_app_version")]
50+
[JsonPropertyName("client_app_version")]
5151
public string ClientAppVersion { get; set; }
52-
[JsonProperty("client_version")]
52+
[JsonPropertyName("client_version")]
5353
public string ClientVersion { get; set; }
54-
[JsonProperty("environment")]
54+
[JsonPropertyName("environment")]
5555
public string Environment { get; set; }
5656

5757
[JsonIgnore]

0 commit comments

Comments
 (0)