upload
napt.upload.manager
Upload orchestrator for NAPT Intune deployment.
Coordinates the full upload pipeline: loading recipe config, inferring the package path, authenticating, parsing the .intunewin file, building app metadata, and executing the Graph API upload flow.
Example
Upload a packaged app to Intune:
upload_package
Upload a packaged app to Microsoft Intune via the Graph API.
Loads the recipe config, infers the .intunewin package path, authenticates using the available Azure credential, parses encryption metadata from the package, and executes the full Graph API upload flow.
The package directory is inferred as packages/{app.id}/{version}/. Run 'napt package' before calling this function.
Authentication is automatic — no configuration required:
- Developers: set AZURE_CLIENT_ID and AZURE_TENANT_ID, complete device code flow
- CI/CD: set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID
- Azure-hosted runners: assign a managed identity to the resource
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file. |
required |
Returns:
| Type | Description |
|---|---|
UploadResult
|
Upload result including the Intune app ID, app name, version, and package path. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the package directory is not found, or detection/ requirements scripts are absent from the package directory. Run 'napt package' to create or recreate the package. |
AuthError
|
If all Azure credential methods fail. |
NetworkError
|
If Graph API or Azure Blob Storage calls fail. |
PackagingError
|
If the .intunewin file is malformed. |
Example
Upload and print the resulting Intune app ID:
Source code in napt/upload/manager.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
napt.upload.intunewin
Parses .intunewin package files for NAPT upload operations.
A .intunewin file is a ZIP archive created by IntuneWinAppUtil with the following structure:
IntuneWinPackage/
Contents/
IntunePackage.intunewin <- encrypted payload
Metadata/
Detection.xml <- encryption metadata
This module extracts the encryption metadata from Detection.xml and provides utilities for extracting the encrypted payload for upload to Azure Blob Storage.
Example
Parse metadata and extract payload:
from pathlib import Path
from napt.upload.intunewin import parse_intunewin, extract_encrypted_payload
metadata = parse_intunewin(
Path("packages/napt-chrome/Invoke-AppDeployToolkit.intunewin")
)
print(f"Encrypted file: {metadata.encrypted_file_name}")
print(f"Encryption key: {metadata.encryption_key}")
IntunewinMetadata
dataclass
Encryption metadata extracted from a .intunewin package.
All fields are sourced from Detection.xml inside the .intunewin ZIP archive. This metadata is required by the Graph API file commit endpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
encrypted_file_name |
str
|
Filename of the encrypted payload inside the Contents/ directory (always "IntunePackage.intunewin"). |
unencrypted_content_size |
int
|
Original size in bytes before encryption. |
file_digest |
str
|
Base64-encoded SHA-256 hash of the encrypted payload. |
file_digest_algorithm |
str
|
Hash algorithm used (always "SHA256"). |
encryption_key |
str
|
Base64-encoded AES-256 encryption key. |
mac_key |
str
|
Base64-encoded HMAC key for MAC verification. |
init_vector |
str
|
Base64-encoded AES initialization vector. |
mac |
str
|
Base64-encoded MAC value for integrity verification. |
profile_identifier |
str
|
Encryption profile version (always "ProfileVersion1"). |
encrypted_file_size |
int
|
Byte size of the encrypted payload file. |
Source code in napt/upload/intunewin.py
parse_intunewin
Parse a .intunewin package and extract encryption metadata.
Reads IntuneWinPackage/Metadata/Detection.xml from inside the .intunewin ZIP and returns all encryption fields required for the Graph API upload flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intunewin_path
|
Path
|
Path to the .intunewin file to parse. |
required |
Returns:
| Type | Description |
|---|---|
IntunewinMetadata
|
Parsed encryption metadata from Detection.xml. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the file is not a valid ZIP, Detection.xml is missing, or required XML fields are absent or malformed. |
Example
Parse an existing package:
Source code in napt/upload/intunewin.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
extract_encrypted_payload
Extract the encrypted payload from a .intunewin package.
Extracts IntuneWinPackage/Contents/IntunePackage.intunewin to the destination directory for upload to Azure Blob Storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intunewin_path
|
Path
|
Path to the .intunewin file. |
required |
dest_dir
|
Path
|
Directory to extract the payload into. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the extracted encrypted payload file. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the file is not a valid ZIP or the payload is missing. |
Source code in napt/upload/intunewin.py
napt.upload.auth
Azure credential acquisition for NAPT Intune upload.
Requires a NAPT app registration in Microsoft Entra ID with the
DeviceManagementApps.ReadWrite.All Microsoft Graph API permission.
See the authentication documentation for setup instructions.
Authentication is selected automatically based on environment variables:
Authentication order
- EnvironmentCredential -- service principal via environment variables. Set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID. Recommended for CI/CD pipelines (GitHub Actions, Azure DevOps, etc.).
- ManagedIdentityCredential -- Azure managed identity. Works automatically on Azure VMs, Azure Container Instances, and Azure-hosted pipeline agents with a managed identity assigned. No credentials to manage.
- DeviceCodeCredential -- interactive device code flow (TTY only). Requires AZURE_CLIENT_ID and AZURE_TENANT_ID to be set (no secret needed). Prints a URL and code; the user completes authentication in any browser. Skipped in CI/CD and when output is redirected.
If all available methods fail, an AuthError is raised with guidance on which environment variables to set.
Example
Acquiring a token for Graph API:
get_credential
Build the Phase 1 credential chain for non-interactive authentication.
Returns a credential that tries service principal auth (via environment
variables) first, then managed identity for Azure-hosted workloads.
Both use the .default scope, suitable for application permissions.
For interactive device code auth, use get_access_token() directly,
which handles Phase 2 automatically when Phase 1 fails.
Returns:
| Type | Description |
|---|---|
ChainedTokenCredential
|
A ChainedTokenCredential for non-interactive authentication. |
Source code in napt/upload/auth.py
get_access_token
Acquire a Microsoft Graph API access token.
Tries credential methods in order until one succeeds:
Phase 1 (always tried):
EnvironmentCredential (service principal via AZURE_CLIENT_ID,
AZURE_CLIENT_SECRET, AZURE_TENANT_ID) then ManagedIdentityCredential.
Both use the .default scope (application permissions).
Phase 2 (only if Phase 1 fails and stdout is a TTY): DeviceCodeCredential using AZURE_CLIENT_ID and AZURE_TENANT_ID. Uses the explicit DeviceManagementApps.ReadWrite.All scope, which triggers a consent prompt on first run.
Returns:
| Type | Description |
|---|---|
str
|
Bearer token string for use in Authorization headers. |
Raises:
| Type | Description |
|---|---|
AuthError
|
If all credential types fail or are unavailable, with guidance on which environment variables to set. |
Example
Get a token and use it in a request:
Source code in napt/upload/auth.py
napt.upload.graph
Microsoft Graph API and Azure Blob Storage client for Intune Win32 app upload.
Implements the full upload flow for a Win32 LOB app:
1. Create Win32 app record in Intune (POST mobileApps)
2. Create a content version (POST contentVersions)
3. Create a file entry and wait for SAS URI (POST files + polling)
4. Upload encrypted payload to Azure Blob Storage (PUT blocks + block list)
5. Commit the uploaded file with encryption metadata (POST commit + polling)
6. Set the committed content version on the app (PATCH mobileApps)
All functions take an access_token as the first argument. Obtain one via napt.upload.auth.get_access_token().
Example
Full upload flow:
from pathlib import Path
from napt.upload.auth import get_access_token
from napt.upload.graph import (
create_win32_app, create_content_version,
create_content_version_file, upload_to_azure_blob,
commit_content_version_file, commit_content_version,
)
from napt.upload.intunewin import parse_intunewin
token = get_access_token()
metadata = parse_intunewin(Path("packages/napt-chrome/144.0.7559.110/Invoke-AppDeployToolkit.intunewin"))
app_id = create_win32_app(token, app_metadata)
cv_id = create_content_version(token, app_id)
file_id, sas_uri = create_content_version_file(token, app_id, cv_id, metadata)
upload_to_azure_blob(sas_uri, Path("/tmp/IntunePackage.intunewin"))
commit_content_version_file(token, app_id, cv_id, file_id, metadata)
commit_content_version(token, app_id, cv_id)
create_win32_app
Create a new Win32 LOB app record in Intune.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
app_metadata
|
dict
|
Win32LobApp JSON payload (display name, install commands, detection rules, etc.). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Graph API object ID of the newly created app. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
ConfigError
|
On 400 (invalid metadata). |
NetworkError
|
On 5xx or connection error. |
Source code in napt/upload/graph.py
create_content_version
Create a new content version for a Win32 app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
app_id
|
str
|
Graph API object ID of the Win32 app. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The content version ID string. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On 5xx or connection error. |
Source code in napt/upload/graph.py
create_content_version_file
create_content_version_file(access_token: str, app_id: str, cv_id: str, metadata: IntunewinMetadata) -> tuple[str, str]
Create a file entry for a content version and wait for the SAS URI.
Posts the file size information to Graph API, then polls until Azure Storage has provisioned a SAS URI for the upload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
app_id
|
str
|
Graph API object ID of the Win32 app. |
required |
cv_id
|
str
|
Content version ID from create_content_version. |
required |
metadata
|
IntunewinMetadata
|
Parsed .intunewin metadata (provides file sizes). |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
A tuple of (file_id, sas_uri) where sas_uri is the Azure Blob Storage SAS URI to upload the encrypted payload to. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On 5xx, connection error, or upload state error. |
Source code in napt/upload/graph.py
upload_to_azure_blob
Upload the encrypted payload to Azure Blob Storage using block blobs.
Splits the file into CHUNK_SIZE chunks, uploads each as a block with a base64-encoded block ID, then commits the block list. Prints an inline progress percentage as each chunk completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sas_uri
|
str
|
Azure Blob Storage SAS URI from create_content_version_file. |
required |
encrypted_payload_path
|
Path
|
Path to the extracted encrypted payload file (IntunePackage.intunewin from inside the .intunewin ZIP). |
required |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If any block upload or the block list commit fails. |
Source code in napt/upload/graph.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
commit_content_version_file
commit_content_version_file(access_token: str, app_id: str, cv_id: str, file_id: str, metadata: IntunewinMetadata) -> None
Commit the uploaded file with encryption metadata, then wait for confirmation.
Sends the encryption key, MAC, IV, and digest to Graph API, then polls until Intune confirms the file is committed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
app_id
|
str
|
Graph API object ID of the Win32 app. |
required |
cv_id
|
str
|
Content version ID. |
required |
file_id
|
str
|
File entry ID from create_content_version_file. |
required |
metadata
|
IntunewinMetadata
|
Parsed .intunewin metadata (provides all encryption fields). |
required |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On 5xx, connection error, or if commit times out. |
Source code in napt/upload/graph.py
commit_content_version
Set the committed content version on the Win32 app.
This is the final step — after calling this, the app is fully published in Intune and available for assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
app_id
|
str
|
Graph API object ID of the Win32 app. |
required |
cv_id
|
str
|
Content version ID to mark as committed. |
required |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On 5xx or connection error. |