A free open source IT asset/license management system
Possible fix for #19849 - use beta API for scope tags
snipe636ca3366dc7
diff --git a/app/SyncAdapters/Intune/IntuneClient.php b/app/SyncAdapters/Intune/IntuneClient.phpindex 299481b6ff..d398f5ff17 100644--- a/app/SyncAdapters/Intune/IntuneClient.php+++ b/app/SyncAdapters/Intune/IntuneClient.php@@ -21,6 +21,15 @@ use Illuminate\Support\Facades\Http;* `loginBaseUrl` constructor args let the adapter derive the login* host from the Graph host so the settings-page URL field controls* both endpoints.+ *+ * Graph API version: the unfiltered device pull uses `/v1.0/`, the+ * stable surface. Two call sites fall over to `/beta/` because the+ * stable version does not expose the data they need: the+ * composed-notes push on `updateManagedDevice()` (notes is a+ * beta-only writable field), and the entire scope-tag filter flow+ * (roleScopeTags resource and the roleScopeTagIds filter on+ * managedDevices). Microsoft does not guarantee beta stability, so a+ * Graph side change can break those paths without warning.*/class IntuneClient{@@ -53,7 +62,14 @@ class IntuneClientpublic function managedDevices(?array $scopeTagIds = null): iterable{$graphOrigin = $this->origin($this->graphBaseUrl);- $url = rtrim($this->graphBaseUrl, '/').'/v1.0/deviceManagement/managedDevices';++ // roleScopeTagIds filtering lives on the beta surface. On+ // /v1.0/ the field isn't exposed, so a $filter against it+ // 400s. Fall over to /beta/ only when a filter is in use so+ // tenants that don't touch scope tags stay on the stable+ // surface.+ $apiVersion = (is_array($scopeTagIds) && $scopeTagIds !== []) ? 'beta' : 'v1.0';+ $url = rtrim($this->graphBaseUrl, '/').'/'.$apiVersion.'/deviceManagement/managedDevices';$query = [];if (is_array($scopeTagIds) && $scopeTagIds !== []) {@@ -91,7 +107,10 @@ class IntuneClientpublic function roleScopeTags(): array{$graphOrigin = $this->origin($this->graphBaseUrl);- $url = rtrim($this->graphBaseUrl, '/').'/v1.0/deviceManagement/roleScopeTags';+ // The roleScopeTag resource is only exposed on /beta/. The+ // stable v1.0 surface returns a 400 "Resource not found for+ // the segment 'roleScopeTags'" so there is no fallback.+ $url = rtrim($this->graphBaseUrl, '/').'/beta/deviceManagement/roleScopeTags';$out = [];do {diff --git a/resources/lang/en-US/admin/settings/sync_adapters.php b/resources/lang/en-US/admin/settings/sync_adapters.phpindex 231d99e00e..ad2f56dd75 100644--- a/resources/lang/en-US/admin/settings/sync_adapters.php+++ b/resources/lang/en-US/admin/settings/sync_adapters.php@@ -267,7 +267,7 @@ return ['intune_fetch_per_device_details_label' => 'Fetch per-device details on every sync (Ethernet MAC + Physical Memory)','intune_fetch_per_device_details_help' => 'Microsoft Graph does not return Ethernet MAC Address or Physical Memory on the list endpoint we paginate through. Turning this on fires one extra Graph call per managed device at pull time to backfill those two fields. Default off because the extra call per device adds up on large fleets - leave off unless you need those fields populated.','intune_scope_tag_filter_label' => 'Scope tag filter',- 'intune_scope_tag_filter_help' => 'Comma-separated Intune Scope Tag names (or IDs) to limit the sync to. Devices with any of these tags are synced, everything else is skipped at the Graph API layer so unrelated devices never leave Microsoft. Leave blank to sync every device the app registration can see. Scope tags are managed under Tenant admin -> Roles -> Scope (Tags) in Intune. Example: "Marketing, Engineering".',+ 'intune_scope_tag_filter_help' => 'Comma-separated Intune Scope Tag names (or IDs) to limit the sync to. Devices with any of these tags are synced, everything else is skipped at the Graph API layer so unrelated devices never leave Microsoft. Leave blank to sync every device the app registration can see. Scope tags are managed under Tenant admin -> Roles -> Scope (Tags) in Intune. Example: "Marketing, Engineering". Note: scope tag filtering goes through the Microsoft Graph beta API, which Microsoft does not guarantee stable.','meraki_sm_api_key_help' => 'Generate under your Meraki Dashboard profile -> My Profile -> API access. Needs read access to the target organization (and Systems Manager network access for the devices endpoint).','meraki_sm_organization_id_help' => 'Copy from Organization -> Settings -> Dashboard API access in the Meraki Dashboard, or from any org URL segment after /o/.','workspace_one_tenant_code_help' => 'Find under Groups & Settings -> All Settings -> System -> Advanced -> API -> REST API in your Workspace ONE console.',diff --git a/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php b/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.phpindex a3aa112bbb..cbcd53b513 100644--- a/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php+++ b/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php@@ -152,18 +152,21 @@ class IntuneAdapterTest extends TestCasepublic function test_scope_tag_filter_resolves_names_to_ids_and_sends_odata_filter(){+ // Scope tag flow runs on /beta/. The roleScopeTags resource+ // only lives there (v1.0 400s), and roleScopeTagIds is only+ // filterable on the beta managedDevices surface.$adapter = $this->configuredAdapter(scopeTagFilter: 'Marketing, 7');Http::fake(['*/oauth2/v2.0/token' => Http::response(['access_token' => 'stub-bearer', 'expires_in' => 3600]),- '*/v1.0/deviceManagement/roleScopeTags*' => Http::response([+ '*/beta/deviceManagement/roleScopeTags*' => Http::response(['value' => [['id' => '3', 'displayName' => 'Marketing'],['id' => '7', 'displayName' => 'Engineering'],['id' => '11', 'displayName' => 'Finance'],],]),- '*/v1.0/deviceManagement/managedDevices*' => Http::response([+ '*/beta/deviceManagement/managedDevices*' => Http::response(['value' => [$this->intuneDevice(id: 'guid-marketing', name: 'host-marketing'),],@@ -173,7 +176,7 @@ class IntuneAdapterTest extends TestCaseiterator_to_array($adapter->pull());Http::assertSent(function ($request) {- if (! str_contains($request->url(), '/v1.0/deviceManagement/managedDevices')) {+ if (! str_contains($request->url(), '/beta/deviceManagement/managedDevices')) {return false;}$url = urldecode($request->url());@@ -186,6 +189,8 @@ class IntuneAdapterTest extends TestCasepublic function test_blank_scope_tag_filter_sends_no_odata_filter(){+ // No filter means the unfiltered pull stays on /v1.0/. The+ // beta fall-over only kicks in for the scope-tag flow.$adapter = $this->configuredAdapter(scopeTagFilter: '');Http::fake([@@ -196,9 +201,10 @@ class IntuneAdapterTest extends TestCaseiterator_to_array($adapter->pull());// No roleScopeTags call fired, no $filter param on the devices call.- Http::assertNotSent(fn ($request) => str_contains($request->url(), '/v1.0/deviceManagement/roleScopeTags'));+ Http::assertNotSent(fn ($request) => str_contains($request->url(), 'deviceManagement/roleScopeTags'));Http::assertSent(fn ($request) => str_contains($request->url(), '/v1.0/deviceManagement/managedDevices')&& ! str_contains(urldecode($request->url()), '$filter'));+ Http::assertNotSent(fn ($request) => str_contains($request->url(), '/beta/deviceManagement/managedDevices'));}public function test_unresolved_scope_tag_entry_is_dropped()@@ -209,16 +215,16 @@ class IntuneAdapterTest extends TestCaseHttp::fake(['*/oauth2/v2.0/token' => Http::response(['access_token' => 'stub-bearer', 'expires_in' => 3600]),- '*/v1.0/deviceManagement/roleScopeTags*' => Http::response([+ '*/beta/deviceManagement/roleScopeTags*' => Http::response(['value' => [['id' => '3', 'displayName' => 'Marketing']],]),- '*/v1.0/deviceManagement/managedDevices*' => Http::response(['value' => []]),+ '*/beta/deviceManagement/managedDevices*' => Http::response(['value' => []]),]);iterator_to_array($adapter->pull());Http::assertSent(function ($request) {- if (! str_contains($request->url(), '/v1.0/deviceManagement/managedDevices')) {+ if (! str_contains($request->url(), '/beta/deviceManagement/managedDevices')) {return false;}$url = urldecode($request->url());