@microsoft/power-apps-native-auth 0.3.6 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,14 @@ import IntuneMAMSwift
4
4
 
5
5
  // MARK: - Error helpers
6
6
 
7
+ private let expoMsalIntuneErrorDomain = "ExpoMsalIntune"
8
+ private let msalInitErrorCode = 1001
9
+ private let noViewControllerErrorCode = 1002
10
+ private let msalInteractiveErrorCode = 1003
11
+ private let msalSilentInteractionRequiredErrorCode = 1004
12
+ private let msalSilentErrorCode = 1005
13
+ private let msalSignoutErrorCode = 1006
14
+
7
15
  private enum MsalIntuneError: Error {
8
16
  case notInitialized
9
17
  case accountNotFound(String)
@@ -58,11 +66,7 @@ public class ExpoMsalIntuneModule: Module {
58
66
  (clientId: String, authority: String, redirectUri: String, useEmbeddedWebView: Bool, useBroker: Bool) in
59
67
 
60
68
  guard let authorityURL = URL(string: authority) else {
61
- throw NSError(
62
- domain: "ExpoMsalIntune",
63
- code: -1,
64
- userInfo: [NSLocalizedDescriptionKey: "Invalid authority URL: \(authority)"]
65
- )
69
+ throw Self.nativeError(code: -1, message: "Invalid authority URL: \(authority)")
66
70
  }
67
71
 
68
72
  // The E2E release artifact must keep authentication inside the app so
@@ -102,12 +106,15 @@ public class ExpoMsalIntuneModule: Module {
102
106
  // The wrap pipeline adds the required msauth.{bundleId}://auth URL scheme
103
107
  // to Info.plist and CFBundleURLTypes — that's what makes the broker
104
108
  // callback possible at runtime.
105
- MSALGlobalConfig.brokerAvailability = useBroker ? .auto : .none
109
+ MSALGlobalConfig.brokerAvailability = self.useBroker ? .auto : .none
106
110
  do {
107
111
  self.pca = try MSALPublicClientApplication(configuration: config)
108
112
  } catch let err as NSError {
109
- let details = "domain=\(err.domain) code=\(err.code) userInfo=\(err.userInfo)"
110
- throw MsalIntuneError.intuneError("MSAL PCA init failed: \(details)")
113
+ throw Self.nativeMsalError(
114
+ code: msalInitErrorCode,
115
+ operation: "MSAL PCA init",
116
+ error: err
117
+ )
111
118
  }
112
119
 
113
120
  // Persist the resolved MSAL parameters so out-of-process / background
@@ -119,8 +126,8 @@ public class ExpoMsalIntuneModule: Module {
119
126
  clientId: clientId,
120
127
  redirectUri: iosRedirectUri,
121
128
  authority: authority,
122
- useEmbeddedWebView: useEmbeddedWebView,
123
- useBroker: useBroker
129
+ useEmbeddedWebView: self.useEmbeddedWebView,
130
+ useBroker: self.useBroker
124
131
  )
125
132
  }
126
133
 
@@ -139,8 +146,8 @@ public class ExpoMsalIntuneModule: Module {
139
146
  DispatchQueue.main.async {
140
147
  guard let viewController = self.topViewController() else {
141
148
  continuation.resume(throwing: NSError(
142
- domain: "ExpoMsalIntune",
143
- code: -2,
149
+ domain: expoMsalIntuneErrorDomain,
150
+ code: noViewControllerErrorCode,
144
151
  userInfo: [NSLocalizedDescriptionKey: "No view controller available for interactive sign-in"]
145
152
  ))
146
153
  return
@@ -167,8 +174,11 @@ public class ExpoMsalIntuneModule: Module {
167
174
 
168
175
  pca.acquireToken(with: params) { result, error in
169
176
  if let error = error as NSError? {
170
- let details = "domain=\(error.domain) code=\(error.code) userInfo=\(error.userInfo)"
171
- continuation.resume(throwing: MsalIntuneError.intuneError("MSAL acquireToken failed: \(details)"))
177
+ continuation.resume(throwing: Self.nativeMsalError(
178
+ code: msalInteractiveErrorCode,
179
+ operation: "MSAL acquireToken",
180
+ error: error
181
+ ))
172
182
  return
173
183
  }
174
184
  guard let result = result else {
@@ -203,9 +213,17 @@ public class ExpoMsalIntuneModule: Module {
203
213
  // fall back to interactive.
204
214
  if nsError.domain == MSALErrorDomain,
205
215
  nsError.code == MSALError.interactionRequired.rawValue {
206
- continuation.resume(throwing: MsalIntuneError.interactionRequired)
216
+ continuation.resume(throwing: Self.nativeMsalError(
217
+ code: msalSilentInteractionRequiredErrorCode,
218
+ operation: "MSAL acquireTokenSilent interactionRequired",
219
+ error: nsError
220
+ ))
207
221
  } else {
208
- continuation.resume(throwing: error)
222
+ continuation.resume(throwing: Self.nativeMsalError(
223
+ code: msalSilentErrorCode,
224
+ operation: "MSAL acquireTokenSilent",
225
+ error: nsError
226
+ ))
209
227
  }
210
228
  return
211
229
  }
@@ -291,7 +309,11 @@ public class ExpoMsalIntuneModule: Module {
291
309
 
292
310
  pca.signout(with: account, signoutParameters: params) { _, error in
293
311
  if let error = error {
294
- continuation.resume(throwing: error)
312
+ continuation.resume(throwing: Self.nativeMsalError(
313
+ code: msalSignoutErrorCode,
314
+ operation: "MSAL signout",
315
+ error: error as NSError
316
+ ))
295
317
  } else {
296
318
  continuation.resume()
297
319
  }
@@ -356,6 +378,26 @@ public class ExpoMsalIntuneModule: Module {
356
378
 
357
379
  // MARK: - Private helpers
358
380
 
381
+ private static func nativeError(code: Int, message: String) -> NSError {
382
+ NSError(
383
+ domain: expoMsalIntuneErrorDomain,
384
+ code: code,
385
+ userInfo: [NSLocalizedDescriptionKey: message]
386
+ )
387
+ }
388
+
389
+ private static func nativeMsalError(code: Int, operation: String, error: NSError) -> NSError {
390
+ let message = "\(operation) failed: domain=\(error.domain) code=\(error.code) message=\(error.localizedDescription)"
391
+ return NSError(
392
+ domain: expoMsalIntuneErrorDomain,
393
+ code: code,
394
+ userInfo: [
395
+ NSLocalizedDescriptionKey: message,
396
+ NSUnderlyingErrorKey: error,
397
+ ]
398
+ )
399
+ }
400
+
359
401
  private func cacheOperationsPca() throws -> MSALPublicClientApplication? {
360
402
  if let pca {
361
403
  return pca
package/lib/NOTICE.txt CHANGED
@@ -2,4 +2,4 @@ NOTICES
2
2
 
3
3
  This repository incorporates material as listed below or described in the code.
4
4
 
5
- @microsoft/power-apps-native-auth@0.3.6 has no production third-party dependencies.
5
+ @microsoft/power-apps-native-auth@0.3.8 has no production third-party dependencies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/power-apps-native-auth",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Expo native module: MSAL authentication + Microsoft Intune MAM for iOS and Android",
5
5
  "author": "Microsoft Corporation",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -37,8 +37,8 @@
37
37
  "expo-module.config.json"
38
38
  ],
39
39
  "scripts": {
40
- "prepack": "bob build && node ../../scripts/notices.js",
41
- "build": "bob build && node ../../scripts/notices.js",
40
+ "prepack": "bob build && node ../../scripts/package-build/notices.js",
41
+ "build": "bob build && node ../../scripts/package-build/notices.js",
42
42
  "type-check": "tsc --noEmit",
43
43
  "setup:ios": "node scripts/setup-ios-frameworks.js",
44
44
  "setup:android": "node scripts/setup-android-sdk.js",
@@ -51,6 +51,7 @@
51
51
  "react-native": ">=0.83.4"
52
52
  },
53
53
  "devDependencies": {
54
+ "@microsoft/power-apps-cli": "0.15.3",
54
55
  "expo-modules-core": "55.0.25",
55
56
  "typescript": "5.9.3"
56
57
  },