Skip to content

Commit db87c78

Browse files
committed
ios and android
1 parent 4630e2c commit db87c78

File tree

5 files changed

+63
-60
lines changed

5 files changed

+63
-60
lines changed

src/client/Microsoft.Identity.Client/ManagedIdentity/AbstractManagedIdentity.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
using System.Net;
1313
using Microsoft.Identity.Client.ApiConfig.Parameters;
1414
using System.Text;
15-
#if SUPPORTS_SYSTEM_TEXT_JSON
1615
using System.Text.Json;
17-
#else
18-
using Microsoft.Identity.Json;
19-
#endif
2016

2117
namespace Microsoft.Identity.Client.ManagedIdentity
2218
{

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
4+
using System.Text.Json;
85
using System.Threading;
9-
using System.Threading.Tasks;
106
using Android.Content;
117
using Microsoft.Identity.Client.Core;
128
using Microsoft.Identity.Client.Http;
139
using Microsoft.Identity.Client.Internal.Broker;
1410
using Microsoft.Identity.Client.OAuth2;
15-
using Microsoft.Identity.Json.Linq;
11+
using Microsoft.Identity.Client.Utils;
1612

1713
namespace Microsoft.Identity.Client.Platforms.Android.Broker
1814
{
@@ -58,14 +54,15 @@ internal static void SetBrokerResult(Intent data, int resultCode, ILoggerAdapter
5854
case (int)BrokerResponseCode.BrowserCodeError:
5955
unreliableLogger?.Info("[Android broker] Response received - error. ");
6056

61-
dynamic errorResult = JObject.Parse(data.GetStringExtra(BrokerConstants.BrokerResultV2));
57+
var errorResult = JsonHelper.DeserializeFromJson<BrokerErrorResult>
58+
(data.GetStringExtra(BrokerConstants.BrokerResultV2));
6259

6360
string error;
6461
string errorDescription;
6562
if (errorResult != null)
6663
{
67-
error = errorResult[BrokerResponseConst.BrokerErrorCode]?.ToString();
68-
errorDescription = errorResult[BrokerResponseConst.BrokerErrorMessage]?.ToString();
64+
error = errorResult.BrokerErrorCode;
65+
errorDescription = errorResult.BrokerErrorMessage;
6966

7067
unreliableLogger?.Error($"[Android broker] error: {error} errorDescription {errorDescription}. ");
7168
}
@@ -76,21 +73,22 @@ internal static void SetBrokerResult(Intent data, int resultCode, ILoggerAdapter
7673
unreliableLogger?.Error("[Android broker] Error response received, but not error could be extracted. ");
7774
}
7875

79-
var httpResponse = new HttpResponse();
80-
//TODO: figure out how to get status code properly deserialized from JObject
81-
httpResponse.Body = errorResult[BrokerResponseConst.BrokerHttpBody]?.ToString();
76+
var httpResponse = new HttpResponse
77+
{
78+
Body = errorResult?.BrokerHttpBody
79+
};
8280

8381
InteractiveBrokerTokenResponse = new MsalTokenResponse
8482
{
8583
Error = error,
8684
ErrorDescription = errorDescription,
87-
SubError = errorResult[BrokerResponseConst.BrokerSubError],
85+
SubError = errorResult?.BrokerSubError,
8886
HttpResponse = httpResponse,
8987
CorrelationId = InteractiveRequestCorrelationId,
90-
TenantId = errorResult[BrokerResponseConst.TenantId]?.ToString(),
91-
Upn = errorResult[BrokerResponseConst.UserName]?.ToString(),
92-
AccountUserId = errorResult[BrokerResponseConst.LocalAccountId]?.ToString(),
93-
AuthorityUrl = errorResult[BrokerResponseConst.Authority]?.ToString(),
88+
TenantId = errorResult?.TenantId,
89+
Upn = errorResult?.UserName,
90+
AccountUserId = errorResult?.LocalAccountId,
91+
AuthorityUrl = errorResult?.Authority,
9492
};
9593
break;
9694
default:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,17 @@ internal class AccountInfo
159159
[JsonPropertyName("environment")]
160160
public string Environment { get; set; }
161161
}
162+
163+
[Preserve(AllMembers = true)]
164+
internal class BrokerErrorResult
165+
{
166+
public string BrokerErrorCode { get; set; }
167+
public string BrokerErrorMessage { get; set; }
168+
public string BrokerHttpBody { get; set; }
169+
public string BrokerSubError { get; set; }
170+
public string TenantId { get; set; }
171+
public string UserName { get; set; }
172+
public string LocalAccountId { get; set; }
173+
public string Authority { get; set; }
174+
}
162175
}

src/client/Microsoft.Identity.Client/Platforms/iOS/IntuneEnrollmentIdHelper.cs

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.Identity.Client.Core;
7-
using Microsoft.Identity.Json;
8-
#if iOS
7+
using System.Text.Json.Serialization;
8+
using Microsoft.Identity.Client.Utils;
99
using Foundation;
10-
#endif
10+
using System.Text.Json;
1111

1212
namespace Microsoft.Identity.Client.Platforms.iOS
1313
{
@@ -18,13 +18,12 @@ internal class IntuneEnrollmentIdHelper
1818

1919
internal static string GetEnrollmentId(ILoggerAdapter logger)
2020
{
21-
#if iOS
2221
var keychainData = GetRawEnrollmentId();
2322
if(!string.IsNullOrEmpty(keychainData))
2423
{
2524
try
2625
{
27-
var enrollmentIDs = JsonConvert.DeserializeObject<EnrollmentIDs>(keychainData);
26+
var enrollmentIDs = JsonHelper.DeserializeFromJson<EnrollmentIDs>(keychainData);
2827

2928
if ((enrollmentIDs?.EnrollmentIds?.Count ?? 0) > 0)
3029
{
@@ -33,69 +32,62 @@ internal static string GetEnrollmentId(ILoggerAdapter logger)
3332
}
3433
catch (JsonException jEx)
3534
{
36-
logger.ErrorPii($"Failed to parse enrollmentID for KeychainData: {keychainData}", string.Empty);
35+
logger.Error($"Failed to parse enrollmentID for KeychainData");
3736
logger.ErrorPii(jEx);
3837

3938
return string.Empty;
4039
}
4140
}
42-
#endif
4341
return string.Empty;
4442
}
4543

4644
internal static string GetRawEnrollmentId()
4745
{
48-
#if iOS
4946
var keychainData = NSUserDefaults.StandardUserDefaults.StringForKey(EnrollmentIdKey);
5047
return keychainData;
51-
#else
52-
return string.Empty;
53-
#endif
5448
}
5549

5650
internal static string GetRawMamResources()
5751
{
5852
var keychainData = NSUserDefaults.StandardUserDefaults.StringForKey(Intune_MamResourceKey);
5953
return keychainData;
6054
}
55+
}
6156

62-
/// <summary>
63-
/// This class corresponds to the EnrollmentIDs entry in the Keychain
64-
/// </summary>
65-
internal class EnrollmentIDs
66-
{
67-
private const string EnrollmentIdsKey = "enrollment_ids";
68-
69-
private const string HomeAccountIdKey = "home_account_id";
57+
/// <summary>
58+
/// This class corresponds to the EnrollmentIDs entry in the Keychain
59+
/// </summary>
60+
internal class EnrollmentIDs
61+
{
62+
[JsonPropertyName("enrollment_ids")]
63+
public List<EnrollmentIdProps> EnrollmentIds { get; set; }
64+
}
7065

71-
private const string TidsKey = "tid";
66+
internal class EnrollmentIdProps
67+
{
68+
private const string HomeAccountIdKey = "home_account_id";
7269

73-
private const string UserIdKey = "user_id";
70+
private const string TidsKey = "tid";
7471

75-
private const string OidKey = "oid";
72+
private const string UserIdKey = "user_id";
7673

77-
private const string EnrollmentIdKey = "enrollment_id";
74+
private const string OidKey = "oid";
7875

79-
internal class EnrollmentIdProps
80-
{
81-
[JsonProperty(PropertyName = HomeAccountIdKey)]
82-
public string HomeAccountId { get; set; }
76+
private const string EnrollmentIdKey = "enrollment_id";
8377

84-
[JsonProperty(PropertyName = TidsKey)]
85-
public string Tid { get; set; }
78+
[JsonPropertyName(HomeAccountIdKey)]
79+
public string HomeAccountId { get; set; }
8680

87-
[JsonProperty(PropertyName = UserIdKey)]
88-
public string UserId { get; set; }
81+
[JsonPropertyName(TidsKey)]
82+
public string Tid { get; set; }
8983

90-
[JsonProperty(PropertyName = OidKey)]
91-
public string Oid { get; set; }
84+
[JsonPropertyName(UserIdKey)]
85+
public string UserId { get; set; }
9286

93-
[JsonProperty(PropertyName = EnrollmentIdKey)]
94-
public string EnrollmentId { get; set; }
95-
}
87+
[JsonPropertyName(OidKey)]
88+
public string Oid { get; set; }
9689

97-
[JsonProperty(PropertyName = EnrollmentIdsKey)]
98-
public List<EnrollmentIdProps> EnrollmentIds { get; set; }
99-
}
90+
[JsonPropertyName(EnrollmentIdKey)]
91+
public string EnrollmentId { get; set; }
10092
}
10193
}

src/client/Microsoft.Identity.Client/json/MsalJsonSerializerContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.Identity.Client.Region;
1717
using Microsoft.Identity.Client.WsTrust;
1818

19+
1920
namespace Microsoft.Identity.Client.Platforms.Json
2021
{
2122
/// <summary>
@@ -43,6 +44,9 @@ namespace Microsoft.Identity.Client.Platforms.Json
4344
[JsonSerializable(typeof(Android.Broker.BrokerErrorResponse))]
4445
[JsonSerializable(typeof(Android.Broker.BrokerRequest))]
4546
[JsonSerializable(typeof(List<Android.Broker.AccountData>))]
47+
#endif
48+
#if iOS
49+
[JsonSerializable(typeof(iOS.EnrollmentIDs))]
4650
#endif
4751
[JsonSourceGenerationOptions]
4852
internal partial class MsalJsonSerializerContext : JsonSerializerContext

0 commit comments

Comments
 (0)