@microsoft/power-apps-native-auth 0.4.0 → 1.0.2
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.
- package/README.md +55 -4
- package/android/build.gradle +8 -6
- package/android/src/main/java/expo/modules/msalintune/ExpoMsalIntuneModule.kt +42 -5
- package/ios/ExpoMsalIntune.podspec +4 -7
- package/ios/ExpoMsalIntuneModule.swift +28 -4
- package/lib/NOTICE.txt +1 -1
- package/package.json +7 -8
- package/scripts/setup-ios-frameworks.js +79 -64
package/README.md
CHANGED
|
@@ -20,10 +20,61 @@ npm run setup --workspace @microsoft/power-apps-native-auth
|
|
|
20
20
|
|
|
21
21
|
## Peer dependencies
|
|
22
22
|
|
|
23
|
-
- `expo` >=
|
|
24
|
-
- `expo-modules-core` >=
|
|
25
|
-
- `react-native` >= 0.
|
|
26
|
-
- `@expo/config-plugins` >=
|
|
23
|
+
- `expo` >= 57.0.21
|
|
24
|
+
- `expo-modules-core` >= 57.0.17
|
|
25
|
+
- `react-native` >= 0.86.3 and < 0.87
|
|
26
|
+
- `@expo/config-plugins` >= 57.0.9
|
|
27
|
+
|
|
28
|
+
### iOS build requirements
|
|
29
|
+
|
|
30
|
+
The Expo 57 target uses Xcode 26.4 (macOS Tahoe 26.2 or later) and iOS 17
|
|
31
|
+
or later. SDK setup pins [Intune iOS SDK 21.8.0](https://github.com/microsoftconnect/ms-intune-app-sdk-ios/releases/tag/21.8.0),
|
|
32
|
+
whose published Swift interface was built with Swift 6.2.4. Intune 21.9.0
|
|
33
|
+
was built with Swift 6.3.3 and is not assumed compatible with the selected
|
|
34
|
+
Xcode 26.4 / Swift 6.3 toolchain without a separate build validation.
|
|
35
|
+
Intune 20.x targets Xcode 16 and must not be reused
|
|
36
|
+
with this build. MSAL is pinned to CocoaPods version `2.16.0`, whose upstream
|
|
37
|
+
source tag is available. The `2.16.1` podspec references an unavailable source
|
|
38
|
+
tag and fails on clean installs; do not replace the pin with a floating 2.x
|
|
39
|
+
constraint. Authentication and MAM are not disabled by pre-release diagnostics.
|
|
40
|
+
|
|
41
|
+
Run `npm run setup:ios --workspace @microsoft/power-apps-native-auth` before
|
|
42
|
+
installing pods. Setup replaces an older cached SDK and records the new version
|
|
43
|
+
only after both frameworks have been installed. Overrides through the first
|
|
44
|
+
argument or `INTUNE_IOS_SDK_VERSION` must be exact 21.x versions and require
|
|
45
|
+
their own native compatibility validation; they are not automatic upgrades.
|
|
46
|
+
|
|
47
|
+
Selecting a supported SDK and passing setup tests do not certify a native
|
|
48
|
+
build. Simulator/device launch, sign-in, broker return and MAM behavior still
|
|
49
|
+
need validation with the selected Xcode toolchain.
|
|
50
|
+
|
|
51
|
+
### SDK setup script responsibilities
|
|
52
|
+
|
|
53
|
+
[`scripts/setup-ios-frameworks.js`](scripts/setup-ios-frameworks.js) is run by
|
|
54
|
+
native-build developers/CI before CocoaPods and wrapping. It downloads the
|
|
55
|
+
selected framework release into the auth package's ignored `ios/Frameworks/`
|
|
56
|
+
directory; it is not part of `/check-updates` or a running customer's app.
|
|
57
|
+
|
|
58
|
+
| Function | Purpose and safety boundary |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `assertSupportedVersion` | Require an exact supported 21.x SDK version; reject incompatible families/ranges rather than selecting a floating release |
|
|
61
|
+
| `frameworksPresent` | Check both required framework directories, not just a version marker |
|
|
62
|
+
| `isInstalled` | Reuse a matching installation only when its sentinel and both frameworks agree |
|
|
63
|
+
| `download` | Download the selected archive with bounded redirects/timeout; propagate transport/HTTP failures |
|
|
64
|
+
| `installFrameworks` | Require both extracted framework directories, invalidate the old success marker, copy both frameworks, then record the version |
|
|
65
|
+
| `main` | Select explicit/environment/default version, use valid cached contents or download/extract/install, and remove its own temporary directory |
|
|
66
|
+
|
|
67
|
+
The runtime fingerprint includes this script's complete source because its SDK
|
|
68
|
+
pin selects native binaries. These function notes live here to avoid changing
|
|
69
|
+
that fingerprint merely to add comments to the script. Changing its implementation
|
|
70
|
+
or selected SDK still requires intentional native compatibility preparation and
|
|
71
|
+
rebuilt binaries.
|
|
72
|
+
|
|
73
|
+
Android fingerprinting likewise includes the complete
|
|
74
|
+
[`scripts/setup-android-sdk.js`](scripts/setup-android-sdk.js) source and excludes
|
|
75
|
+
its downloaded `android/libs/` contents, including the version marker. Running
|
|
76
|
+
SDK setup must not change compatibility metadata; changing the setup pin still
|
|
77
|
+
does. Authored Android sources and Gradle declarations remain fingerprinted.
|
|
27
78
|
|
|
28
79
|
## Usage
|
|
29
80
|
|
package/android/build.gradle
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
ext.kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.
|
|
2
|
+
ext.kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '2.1.20'
|
|
3
3
|
repositories {
|
|
4
4
|
mavenCentral()
|
|
5
5
|
google()
|
|
6
6
|
}
|
|
7
7
|
dependencies {
|
|
8
|
-
classpath("com.android.tools.build:gradle:8.
|
|
8
|
+
classpath("com.android.tools.build:gradle:8.12.0")
|
|
9
9
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -18,11 +18,11 @@ def safeExtGet(prop, fallback) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
android {
|
|
21
|
-
compileSdkVersion safeExtGet('compileSdkVersion',
|
|
21
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 36)
|
|
22
22
|
|
|
23
23
|
defaultConfig {
|
|
24
24
|
minSdkVersion safeExtGet('minSdkVersion', 26)
|
|
25
|
-
targetSdkVersion safeExtGet('targetSdkVersion',
|
|
25
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 36)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
compileOptions {
|
|
@@ -57,8 +57,10 @@ dependencies {
|
|
|
57
57
|
implementation project(':expo-modules-core')
|
|
58
58
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
59
59
|
|
|
60
|
-
// MSAL Android
|
|
61
|
-
|
|
60
|
+
// MSAL Android (com.microsoft.identity.client:msal on Maven Central).
|
|
61
|
+
// SDL requires 8.0.3 or later. 8.x needs minSdk 24, AGP 8.10+ and compileSdk 36,
|
|
62
|
+
// all provided by the Expo SDK 57 / React Native 0.86 root project.
|
|
63
|
+
implementation 'com.microsoft.identity.client:msal:8.6.0'
|
|
62
64
|
|
|
63
65
|
// Microsoft Intune MAM SDK for Android.
|
|
64
66
|
// NOT published to any public Maven feed — downloaded from GitHub by
|
|
@@ -19,6 +19,8 @@ import org.json.JSONArray
|
|
|
19
19
|
import org.json.JSONObject
|
|
20
20
|
import java.io.File
|
|
21
21
|
import java.security.MessageDigest
|
|
22
|
+
import java.net.URI
|
|
23
|
+
import java.util.UUID
|
|
22
24
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
23
25
|
import java.util.concurrent.atomic.AtomicInteger
|
|
24
26
|
|
|
@@ -29,6 +31,8 @@ private const val FORCE_ACCOUNT_SELECTION = "force_account_selection"
|
|
|
29
31
|
class ExpoMsalIntuneModule : Module() {
|
|
30
32
|
|
|
31
33
|
private var pca: IMultipleAccountPublicClientApplication? = null
|
|
34
|
+
@Volatile private var currentAuthority: String? = null
|
|
35
|
+
@Volatile private var authorityTenantId: String? = null
|
|
32
36
|
private val initializationGeneration = AtomicInteger(0)
|
|
33
37
|
private val initializationLock = Any()
|
|
34
38
|
|
|
@@ -141,6 +145,8 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
141
145
|
if (initializationGeneration.get() != generation) false
|
|
142
146
|
else {
|
|
143
147
|
pca = app
|
|
148
|
+
currentAuthority = authority
|
|
149
|
+
authorityTenantId = tenantIdFromAuthority(authority)
|
|
144
150
|
configFile.copyTo(File(appCtx.cacheDir, "msal_config.json"), overwrite = true)
|
|
145
151
|
true
|
|
146
152
|
}
|
|
@@ -166,6 +172,8 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
166
172
|
if (initializationGeneration.get() != generation) false
|
|
167
173
|
else {
|
|
168
174
|
pca = app
|
|
175
|
+
currentAuthority = authority
|
|
176
|
+
authorityTenantId = tenantIdFromAuthority(authority)
|
|
169
177
|
configFile.copyTo(File(appCtx.cacheDir, "msal_config.json"), overwrite = true)
|
|
170
178
|
true
|
|
171
179
|
}
|
|
@@ -267,7 +275,7 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
267
275
|
val params = AcquireTokenSilentParameters.Builder()
|
|
268
276
|
.withScopes(scopes)
|
|
269
277
|
.forAccount(account)
|
|
270
|
-
.fromAuthority(account.authority)
|
|
278
|
+
.fromAuthority(currentAuthority ?: account.authority)
|
|
271
279
|
.forceRefresh(forceRefresh)
|
|
272
280
|
.withCallback(object : SilentAuthenticationCallback {
|
|
273
281
|
override fun onSuccess(result: IAuthenticationResult) {
|
|
@@ -447,7 +455,7 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
447
455
|
// the async RemoveAccountCallback deadlocks under Bridgeless, leaving
|
|
448
456
|
// isLoading=true after signout so the loading spinner never clears.
|
|
449
457
|
try {
|
|
450
|
-
Log.d(TAG, "signOut: removing account
|
|
458
|
+
Log.d(TAG, "signOut: removing account")
|
|
451
459
|
client.removeAccount(account)
|
|
452
460
|
Log.d(TAG, "signOut: account removed successfully")
|
|
453
461
|
promise.resolve(null)
|
|
@@ -580,6 +588,11 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
580
588
|
|
|
581
589
|
private val notInitMsg = "ExpoMsalIntune: call initializeClient() before acquiring tokens"
|
|
582
590
|
|
|
591
|
+
private fun tenantIdFromAuthority(authority: String): String? {
|
|
592
|
+
val authoritySegment = runCatching { URI(authority).path.trim('/').substringAfterLast('/') }.getOrNull()
|
|
593
|
+
return authoritySegment?.takeIf { runCatching { UUID.fromString(it) }.isSuccess }
|
|
594
|
+
}
|
|
595
|
+
|
|
583
596
|
private fun findAccount(
|
|
584
597
|
client: IMultipleAccountPublicClientApplication,
|
|
585
598
|
identifier: String
|
|
@@ -592,21 +605,45 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
592
605
|
}
|
|
593
606
|
}
|
|
594
607
|
|
|
595
|
-
private fun serializeAccount(account: IAccount): Map<String, Any> {
|
|
608
|
+
private fun serializeAccount(account: IAccount, resultTenantId: String? = null): Map<String, Any> {
|
|
596
609
|
val claims = try {
|
|
597
610
|
val claimsMap = account.claims ?: emptyMap<String, Any>()
|
|
598
611
|
JSONObject(claimsMap).toString()
|
|
599
612
|
} catch (e: Exception) {
|
|
600
613
|
"{}"
|
|
601
614
|
}
|
|
615
|
+
val tenantId = resultTenantId?.takeIf { it.isNotBlank() }
|
|
616
|
+
?: configuredTenantIdForAccount(account)
|
|
617
|
+
?: account.tenantId?.takeIf { it.isNotBlank() }
|
|
618
|
+
?: homeTenantIdForAccount(account)
|
|
619
|
+
?: ""
|
|
602
620
|
return mapOf(
|
|
603
621
|
"identifier" to (account.id ?: ""),
|
|
604
622
|
"username" to (account.username ?: ""),
|
|
605
|
-
"tenantId" to
|
|
623
|
+
"tenantId" to tenantId,
|
|
606
624
|
"claims" to claims,
|
|
607
625
|
)
|
|
608
626
|
}
|
|
609
627
|
|
|
628
|
+
private fun configuredTenantIdForAccount(account: IAccount): String? {
|
|
629
|
+
val configuredTenantId = authorityTenantId ?: return null
|
|
630
|
+
val claimsTenantId = account.claims?.get("tid") as? String
|
|
631
|
+
val matchesAccount = account.tenantId?.equals(configuredTenantId, ignoreCase = true) == true
|
|
632
|
+
|| claimsTenantId?.equals(configuredTenantId, ignoreCase = true) == true
|
|
633
|
+
|| homeTenantIdForAccount(account)?.equals(configuredTenantId, ignoreCase = true) == true
|
|
634
|
+
|| (account as? IMultiTenantAccount)?.tenantProfiles?.keys.orEmpty()
|
|
635
|
+
.any { it.equals(configuredTenantId, ignoreCase = true) }
|
|
636
|
+
return configuredTenantId.takeIf { matchesAccount }
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
private fun homeTenantIdForAccount(account: IAccount): String? {
|
|
640
|
+
val homeAccountId = account.id ?: return null
|
|
641
|
+
val separatorIndex = homeAccountId.lastIndexOf('.')
|
|
642
|
+
if (separatorIndex < 0 || separatorIndex == homeAccountId.lastIndex) return null
|
|
643
|
+
val tenantId = homeAccountId.substring(separatorIndex + 1)
|
|
644
|
+
return tenantId.takeIf { runCatching { UUID.fromString(it) }.isSuccess }
|
|
645
|
+
}
|
|
646
|
+
|
|
610
647
|
private fun serializeResult(result: IAuthenticationResult): Map<String, Any> {
|
|
611
648
|
return mapOf(
|
|
612
649
|
"accessToken" to result.accessToken,
|
|
@@ -615,7 +652,7 @@ class ExpoMsalIntuneModule : Module() {
|
|
|
615
652
|
"idToken" to (result.account.idToken ?: ""),
|
|
616
653
|
"expiresOn" to result.expiresOn.time,
|
|
617
654
|
"scopes" to result.scope.toList(),
|
|
618
|
-
"account" to serializeAccount(result.account),
|
|
655
|
+
"account" to serializeAccount(result.account, result.tenantId),
|
|
619
656
|
)
|
|
620
657
|
}
|
|
621
658
|
|
|
@@ -7,19 +7,16 @@ Pod::Spec.new do |s|
|
|
|
7
7
|
s.author = 'Microsoft'
|
|
8
8
|
s.homepage = 'https://github.com/microsoft/pa-wrap-tools'
|
|
9
9
|
s.license = { :type => 'MIT' }
|
|
10
|
-
s.platforms = { :ios => '
|
|
10
|
+
s.platforms = { :ios => '17.0' }
|
|
11
11
|
s.source = { :path => '.' }
|
|
12
12
|
s.static_framework = true
|
|
13
13
|
|
|
14
14
|
s.dependency 'ExpoModulesCore'
|
|
15
|
-
|
|
16
|
-
s.dependency 'MSAL', '~> 2.10'
|
|
15
|
+
s.dependency 'MSAL', '2.16.0'
|
|
17
16
|
|
|
18
|
-
# IntuneMAMSwift iOS
|
|
17
|
+
# IntuneMAMSwift iOS 21.8.0 requires Xcode 26 and iOS 17+.
|
|
19
18
|
# Vendored locally because IntuneMAMSwift is not published to the public CocoaPods CDN.
|
|
20
|
-
#
|
|
21
|
-
# https://github.com/microsoftconnect/ms-intune-app-sdk-ios/releases
|
|
22
|
-
# and replace the contents of ios/Frameworks/.
|
|
19
|
+
# Run npm run setup:ios after changing the version in scripts/setup-ios-frameworks.js.
|
|
23
20
|
s.vendored_frameworks = 'Frameworks/IntuneMAMSwift.xcframework',
|
|
24
21
|
'Frameworks/IntuneMAMSwiftStub.xcframework'
|
|
25
22
|
|
|
@@ -45,6 +45,7 @@ extension MsalIntuneError: LocalizedError {
|
|
|
45
45
|
public class ExpoMsalIntuneModule: Module {
|
|
46
46
|
private static let forceAccountSelectionKey = "powerapps.native.auth.forceAccountSelection"
|
|
47
47
|
private var pca: MSALPublicClientApplication?
|
|
48
|
+
private var authorityTenantId: String?
|
|
48
49
|
private var initializationGeneration: UInt64 = 0
|
|
49
50
|
private let initializationLock = NSLock()
|
|
50
51
|
/// Stored at initializeClient time; controls which WebView type is used for
|
|
@@ -119,6 +120,7 @@ public class ExpoMsalIntuneModule: Module {
|
|
|
119
120
|
throw MsalIntuneError.intuneError("MSAL initialization was superseded")
|
|
120
121
|
}
|
|
121
122
|
self.pca = initializedPca
|
|
123
|
+
self.authorityTenantId = Self.tenantId(fromAuthorityURL: authorityURL)
|
|
122
124
|
} catch let err as NSError {
|
|
123
125
|
throw Self.nativeMsalError(
|
|
124
126
|
code: msalInitErrorCode,
|
|
@@ -423,6 +425,14 @@ public class ExpoMsalIntuneModule: Module {
|
|
|
423
425
|
)
|
|
424
426
|
}
|
|
425
427
|
|
|
428
|
+
private static func tenantId(fromAuthorityURL authorityUrl: URL) -> String? {
|
|
429
|
+
guard let authoritySegment = authorityUrl.pathComponents.last,
|
|
430
|
+
UUID(uuidString: authoritySegment) != nil else {
|
|
431
|
+
return nil
|
|
432
|
+
}
|
|
433
|
+
return authoritySegment
|
|
434
|
+
}
|
|
435
|
+
|
|
426
436
|
private func cacheOperationsPca() throws -> MSALPublicClientApplication? {
|
|
427
437
|
if let pca {
|
|
428
438
|
return pca
|
|
@@ -500,15 +510,18 @@ public class ExpoMsalIntuneModule: Module {
|
|
|
500
510
|
return account
|
|
501
511
|
}
|
|
502
512
|
|
|
503
|
-
private func serializeAccount(_ account: MSALAccount) -> [String: Any] {
|
|
513
|
+
private func serializeAccount(_ account: MSALAccount, resultTenantId: String? = nil) -> [String: Any] {
|
|
504
514
|
var claims: String = "{}"
|
|
505
515
|
if let rawClaims = account.accountClaims,
|
|
506
516
|
let data = try? JSONSerialization.data(withJSONObject: rawClaims),
|
|
507
517
|
let str = String(data: data, encoding: .utf8) {
|
|
508
518
|
claims = str
|
|
509
519
|
}
|
|
510
|
-
let tenantId =
|
|
511
|
-
?? account
|
|
520
|
+
let tenantId = resultTenantId
|
|
521
|
+
?? configuredTenantId(for: account)
|
|
522
|
+
?? account.accountClaims?["tid"] as? String
|
|
523
|
+
?? account.homeAccountId?.tenantId
|
|
524
|
+
?? account.tenantProfiles?.first(where: { $0.isHomeTenantProfile })?.tenantId
|
|
512
525
|
?? ""
|
|
513
526
|
return [
|
|
514
527
|
"identifier": account.identifier ?? "",
|
|
@@ -518,6 +531,17 @@ public class ExpoMsalIntuneModule: Module {
|
|
|
518
531
|
]
|
|
519
532
|
}
|
|
520
533
|
|
|
534
|
+
private func configuredTenantId(for account: MSALAccount) -> String? {
|
|
535
|
+
guard let configuredTenantId = authorityTenantId else { return nil }
|
|
536
|
+
let claimsTenantId = account.accountClaims?["tid"] as? String
|
|
537
|
+
let matchesAccount = claimsTenantId?.caseInsensitiveCompare(configuredTenantId) == .orderedSame
|
|
538
|
+
|| account.homeAccountId?.tenantId?.caseInsensitiveCompare(configuredTenantId) == .orderedSame
|
|
539
|
+
|| account.tenantProfiles?.contains(where: {
|
|
540
|
+
$0.tenantId?.caseInsensitiveCompare(configuredTenantId) == .orderedSame
|
|
541
|
+
}) == true
|
|
542
|
+
return matchesAccount ? configuredTenantId : nil
|
|
543
|
+
}
|
|
544
|
+
|
|
521
545
|
private func serializeResult(_ result: MSALResult) -> [String: Any] {
|
|
522
546
|
let expiresOn = result.expiresOn.map { $0.timeIntervalSince1970 * 1000 } ?? 0
|
|
523
547
|
return [
|
|
@@ -525,7 +549,7 @@ public class ExpoMsalIntuneModule: Module {
|
|
|
525
549
|
"idToken": result.idToken ?? "",
|
|
526
550
|
"expiresOn": expiresOn,
|
|
527
551
|
"scopes": result.scopes,
|
|
528
|
-
"account": serializeAccount(result.account),
|
|
552
|
+
"account": serializeAccount(result.account, resultTenantId: result.tenantProfile.tenantId),
|
|
529
553
|
]
|
|
530
554
|
}
|
|
531
555
|
|
package/lib/NOTICE.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/power-apps-native-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
@@ -40,20 +40,19 @@
|
|
|
40
40
|
"prepack": "bob build && node ../../scripts/package-build/notices.js",
|
|
41
41
|
"build": "bob build && node ../../scripts/package-build/notices.js",
|
|
42
42
|
"type-check": "tsc --noEmit",
|
|
43
|
+
"test": "node --test test/*.test.js",
|
|
43
44
|
"setup:ios": "node scripts/setup-ios-frameworks.js",
|
|
44
45
|
"setup:android": "node scripts/setup-android-sdk.js",
|
|
45
46
|
"setup": "npm run setup:ios && npm run setup:android"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"@expo/config-plugins": ">=
|
|
49
|
-
"expo": ">=
|
|
50
|
-
"
|
|
51
|
-
"react-native": ">=0.83.4"
|
|
49
|
+
"@expo/config-plugins": ">=57.0.9",
|
|
50
|
+
"expo": ">=57.0.21",
|
|
51
|
+
"react-native": ">=0.86.3 <0.87"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"typescript": "5.9.3"
|
|
54
|
+
"expo-modules-core": "57.0.19",
|
|
55
|
+
"typescript": "6.0.3"
|
|
57
56
|
},
|
|
58
57
|
"keywords": [
|
|
59
58
|
"expo",
|
|
@@ -14,94 +14,109 @@
|
|
|
14
14
|
const https = require('https');
|
|
15
15
|
const fs = require('fs');
|
|
16
16
|
const path = require('path');
|
|
17
|
-
const {
|
|
17
|
+
const { execFileSync } = require('child_process');
|
|
18
|
+
const { pipeline } = require('stream/promises');
|
|
18
19
|
const os = require('os');
|
|
19
20
|
|
|
20
|
-
const DEFAULT_VERSION = '
|
|
21
|
-
const version = process.argv[2] || process.env.INTUNE_IOS_SDK_VERSION || DEFAULT_VERSION;
|
|
22
|
-
|
|
21
|
+
const DEFAULT_VERSION = '21.8.0';
|
|
23
22
|
const REPO = 'microsoftconnect/ms-intune-app-sdk-ios';
|
|
24
|
-
const DOWNLOAD_URL = `https://github.com/${REPO}/archive/refs/tags/${version}.zip`;
|
|
25
|
-
|
|
26
23
|
const FRAMEWORKS = ['IntuneMAMSwift.xcframework', 'IntuneMAMSwiftStub.xcframework'];
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Check if already present
|
|
34
|
-
const currentVersion = fs.existsSync(sentinelPath)
|
|
35
|
-
? fs.readFileSync(sentinelPath, 'utf8').trim()
|
|
36
|
-
: null;
|
|
37
|
-
const allPresent = currentVersion === version
|
|
38
|
-
&& FRAMEWORKS.every(f => fs.existsSync(path.join(frameworksDir, f)));
|
|
39
|
-
if (allPresent) {
|
|
40
|
-
console.log(`✅ IntuneMAMSwift ${version} xcframeworks already present in ios/Frameworks/`);
|
|
41
|
-
process.exit(0);
|
|
25
|
+
function assertSupportedVersion(version) {
|
|
26
|
+
if (typeof version !== 'string' || !/^21\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(version)) {
|
|
27
|
+
throw new Error('This Xcode 26 build requires an exact Intune iOS SDK 21.x version (for example 21.8.0); SDK 20.x targets Xcode 16.');
|
|
28
|
+
}
|
|
42
29
|
}
|
|
43
30
|
|
|
44
|
-
|
|
31
|
+
function frameworksPresent(directory) {
|
|
32
|
+
return FRAMEWORKS.every(framework =>
|
|
33
|
+
fs.existsSync(path.join(directory, framework))
|
|
34
|
+
&& fs.statSync(path.join(directory, framework)).isDirectory());
|
|
35
|
+
}
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
function isInstalled(frameworksDir, version) {
|
|
38
|
+
assertSupportedVersion(version);
|
|
39
|
+
const sentinelPath = path.join(frameworksDir, '.sdk-version');
|
|
40
|
+
return fs.existsSync(sentinelPath)
|
|
41
|
+
&& fs.readFileSync(sentinelPath, 'utf8').trim() === version
|
|
42
|
+
&& frameworksPresent(frameworksDir);
|
|
43
|
+
}
|
|
48
44
|
|
|
49
|
-
function download(url, dest, redirects = 0) {
|
|
45
|
+
async function download(url, dest, redirects = 0) {
|
|
50
46
|
if (redirects > 5) throw new Error('Too many redirects');
|
|
51
47
|
return new Promise((resolve, reject) => {
|
|
52
|
-
const
|
|
53
|
-
https.get(url, (res) => {
|
|
48
|
+
const request = https.get(url, (res) => {
|
|
54
49
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
res.resume();
|
|
51
|
+
if (!res.headers.location) {
|
|
52
|
+
reject(new Error(`Missing redirect location from ${url}`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
download(new URL(res.headers.location, url), dest, redirects + 1).then(resolve, reject);
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
58
|
if (res.statusCode !== 200) {
|
|
59
|
+
res.resume();
|
|
61
60
|
reject(new Error(`HTTP ${res.statusCode} from ${url}`));
|
|
62
61
|
return;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}).on('error',
|
|
67
|
-
|
|
68
|
-
reject(err);
|
|
69
|
-
});
|
|
63
|
+
const file = fs.createWriteStream(dest);
|
|
64
|
+
pipeline(res, file).then(resolve, reject);
|
|
65
|
+
}).on('error', reject);
|
|
66
|
+
request.setTimeout(60000, () => request.destroy(new Error('Intune SDK download timed out')));
|
|
70
67
|
});
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
execSync(`cp -R "${src}" "${dest}"`);
|
|
92
|
-
console.log(`✅ Copied ${framework}`);
|
|
93
|
-
}
|
|
70
|
+
function installFrameworks(extractedRoot, frameworksDir, version) {
|
|
71
|
+
assertSupportedVersion(version);
|
|
72
|
+
if (!frameworksPresent(extractedRoot)) {
|
|
73
|
+
throw new Error(`Expected both Intune xcframework directories in the release archive at ${extractedRoot}`);
|
|
74
|
+
}
|
|
75
|
+
fs.mkdirSync(frameworksDir, { recursive: true });
|
|
76
|
+
const sentinelPath = path.join(frameworksDir, '.sdk-version');
|
|
77
|
+
// A partial copy must never leave a successful installation marker.
|
|
78
|
+
fs.rmSync(sentinelPath, { force: true });
|
|
79
|
+
for (const framework of FRAMEWORKS) {
|
|
80
|
+
const dest = path.join(frameworksDir, framework);
|
|
81
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
82
|
+
fs.cpSync(path.join(extractedRoot, framework), dest, { recursive: true, verbatimSymlinks: true });
|
|
83
|
+
console.log(`✅ Copied ${framework}`);
|
|
84
|
+
}
|
|
85
|
+
fs.writeFileSync(sentinelPath, version + '\n', 'utf8');
|
|
86
|
+
}
|
|
94
87
|
|
|
95
|
-
|
|
88
|
+
async function main() {
|
|
89
|
+
const version = process.argv[2] || process.env.INTUNE_IOS_SDK_VERSION || DEFAULT_VERSION;
|
|
90
|
+
assertSupportedVersion(version);
|
|
91
|
+
const frameworksDir = path.join(__dirname, '..', 'ios', 'Frameworks');
|
|
92
|
+
if (isInstalled(frameworksDir, version)) {
|
|
93
|
+
console.log(`✅ IntuneMAMSwift ${version} xcframeworks already present in ios/Frameworks/`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
const downloadUrl = `https://github.com/${REPO}/archive/refs/tags/${version}.zip`;
|
|
98
|
+
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'intune-ios-sdk-'));
|
|
99
|
+
try {
|
|
100
|
+
const tmpZip = path.join(temporaryDirectory, 'sdk.zip');
|
|
101
|
+
console.log(`⬇️ Downloading IntuneMAMSwift ${version} from GitHub...`);
|
|
102
|
+
console.log(` ${downloadUrl}`);
|
|
103
|
+
await download(downloadUrl, tmpZip);
|
|
104
|
+
console.log('📦 Extracting...');
|
|
105
|
+
execFileSync('unzip', ['-q', tmpZip, '-d', temporaryDirectory], { stdio: 'inherit' });
|
|
106
|
+
installFrameworks(path.join(temporaryDirectory, `ms-intune-app-sdk-ios-${version}`), frameworksDir, version);
|
|
100
107
|
|
|
101
108
|
console.log(`\n✅ IntuneMAMSwift ${version} xcframeworks installed to ios/Frameworks/`);
|
|
102
109
|
console.log(' You can now run: npx expo run:ios\n');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
process.exit(1);
|
|
110
|
+
} finally {
|
|
111
|
+
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
106
112
|
}
|
|
107
|
-
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = { DEFAULT_VERSION, FRAMEWORKS, assertSupportedVersion, isInstalled, installFrameworks };
|
|
116
|
+
|
|
117
|
+
if (require.main === module) {
|
|
118
|
+
main().catch(err => {
|
|
119
|
+
console.error(`\n❌ setup:ios failed: ${err.message}`);
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
});
|
|
122
|
+
}
|