Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 618d1be

Browse files
committed
added sample.json
1 parent 7a1b486 commit 618d1be

File tree

2 files changed

+115
-39
lines changed

2 files changed

+115
-39
lines changed

4-Deployment/1-deploy-storage/AppCreationScripts/Configure.ps1

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -232,31 +232,27 @@ Function ConfigureApplications
232232

233233
# Create the service AAD application
234234
Write-Host "Creating the AAD application (msal-node-api)"
235+
235236
# create the application
236237
$serviceAadApplication = New-MgApplication -DisplayName "msal-node-api" `
237-
-Web `
238-
@{ `
239-
} `
240238
-Api `
241239
@{ `
242240
RequestedAccessTokenVersion = 2 `
243241
} `
244242
-SignInAudience AzureADMyOrg `
245243
#end of command
246-
$currentAppId = $serviceAadApplication.AppId
247-
$currentAppObjectId = $serviceAadApplication.Id
248-
249-
$serviceIdentifierUri = 'api://'+$currentAppId
250-
Update-MgApplication -ApplicationId $currentAppObjectId -IdentifierUris @($serviceIdentifierUri)
244+
$serviceIdentifierUri = 'api://'+$serviceAadApplication.AppId
245+
Update-MgApplication -ApplicationId $serviceAadApplication.Id -IdentifierUris @($serviceIdentifierUri)
251246

252-
# create the service principal of the newly created application
247+
# create the service principal of the newly created application
248+
$currentAppId = $serviceAadApplication.AppId
253249
$serviceServicePrincipal = New-MgServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
254250

255251
# add the user running the script as an app owner if needed
256-
$owner = Get-MgApplicationOwner -ApplicationId $currentAppObjectId
252+
$owner = Get-MgApplicationOwner -ApplicationId $serviceAadApplication.Id
257253
if ($owner -eq $null)
258254
{
259-
New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
255+
New-MgApplicationOwnerByRef -ApplicationId $serviceAadApplication.Id -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
260256
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($serviceServicePrincipal.DisplayName)'"
261257
}
262258

@@ -271,7 +267,7 @@ Function ConfigureApplications
271267

272268
$newClaim = CreateOptionalClaim -name "idtyp"
273269
$optionalClaims.AccessToken += ($newClaim)
274-
Update-MgApplication -ApplicationId $currentAppObjectId -OptionalClaims $optionalClaims
270+
Update-MgApplication -ApplicationId $serviceAadApplication.Id -OptionalClaims $optionalClaims
275271

276272
# rename the user_impersonation scope if it exists to match the readme steps or add a new scope
277273

@@ -285,10 +281,10 @@ Function ConfigureApplications
285281
# disable the scope
286282
$scope.IsEnabled = $false
287283
$scopes.Add($scope)
288-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @($scopes)}
284+
Update-MgApplication -ApplicationId $serviceAadApplication.Id -Api @{Oauth2PermissionScopes = @($scopes)}
289285

290286
# clear the scope
291-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @()}
287+
Update-MgApplication -ApplicationId $serviceAadApplication.Id -Api @{Oauth2PermissionScopes = @()}
292288
}
293289

294290
$scopes = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphPermissionScope]
@@ -301,46 +297,45 @@ Function ConfigureApplications
301297
$scopes.Add($scope)
302298

303299
# add/update scopes
304-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @($scopes)}
300+
Update-MgApplication -ApplicationId $serviceAadApplication.Id -Api @{Oauth2PermissionScopes = @($scopes)}
305301
Write-Host "Done creating the service application (msal-node-api)"
306302

307303
# URL of the AAD application in the Azure portal
308-
# Future? $servicePortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$currentAppId+"/objectId/"+$currentAppObjectId+"/isMSAApp/"
309-
$servicePortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$currentAppId+"/objectId/"+$currentAppObjectId+"/isMSAApp/"
304+
# Future? $servicePortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.Id+"/isMSAApp/"
305+
$servicePortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.Id+"/isMSAApp/"
310306

311307
Add-Content -Value "<tr><td>service</td><td>$currentAppId</td><td><a href='$servicePortalUrl'>msal-node-api</a></td></tr>" -Path createdApps.html
312308

313309
# print the registered app portal URL for any further navigation
314-
Write-Host "Successfully registered and configured that app registration for 'msal-node-api' at `n $servicePortalUrl" -ForegroundColor Green
310+
Write-Host "Successfully registered and configured that app registration for 'msal-node-api' at `n $servicePortalUrl" -ForegroundColor Red
315311

316312
# Create the client AAD application
317313
Write-Host "Creating the AAD application (msal-react-spa)"
314+
318315
# create the application
319316
$clientAadApplication = New-MgApplication -DisplayName "msal-react-spa" `
320317
-Spa `
321318
@{ `
322-
RedirectUris = "http://localhost:3000/"; `
319+
RedirectUris = "http://localhost:3000"; `
323320
} `
324321
-Api `
325322
@{ `
326323
RequestedAccessTokenVersion = 2 `
327324
} `
328325
-SignInAudience AzureADMyOrg `
329326
#end of command
330-
$currentAppId = $clientAadApplication.AppId
331-
$currentAppObjectId = $clientAadApplication.Id
332-
333-
$clientIdentifierUri = 'api://'+$currentAppId
334-
Update-MgApplication -ApplicationId $currentAppObjectId -IdentifierUris @($clientIdentifierUri)
327+
$clientIdentifierUri = 'api://'+$clientAadApplication.AppId
328+
Update-MgApplication -ApplicationId $clientAadApplication.Id -IdentifierUris @($clientIdentifierUri)
335329

336-
# create the service principal of the newly created application
330+
# create the service principal of the newly created application
331+
$currentAppId = $clientAadApplication.AppId
337332
$clientServicePrincipal = New-MgServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
338333

339334
# add the user running the script as an app owner if needed
340-
$owner = Get-MgApplicationOwner -ApplicationId $currentAppObjectId
335+
$owner = Get-MgApplicationOwner -ApplicationId $clientAadApplication.Id
341336
if ($owner -eq $null)
342337
{
343-
New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
338+
New-MgApplicationOwnerByRef -ApplicationId $clientAadApplication.Id -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
344339
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
345340
}
346341

@@ -356,21 +351,21 @@ Function ConfigureApplications
356351
# disable the scope
357352
$scope.IsEnabled = $false
358353
$scopes.Add($scope)
359-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @($scopes)}
354+
Update-MgApplication -ApplicationId $clientAadApplication.Id -Api @{Oauth2PermissionScopes = @($scopes)}
360355

361356
# clear the scope
362-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @()}
357+
Update-MgApplication -ApplicationId $clientAadApplication.Id -Api @{Oauth2PermissionScopes = @()}
363358
}
364359

365360
$scopes = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphPermissionScope]
366361

367362
# add/update scopes
368-
Update-MgApplication -ApplicationId $currentAppObjectId -Api @{Oauth2PermissionScopes = @($scopes)}
363+
Update-MgApplication -ApplicationId $clientAadApplication.Id -Api @{Oauth2PermissionScopes = @($scopes)}
369364
Write-Host "Done creating the client application (msal-react-spa)"
370365

371366
# URL of the AAD application in the Azure portal
372-
# Future? $clientPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$currentAppId+"/objectId/"+$currentAppObjectId+"/isMSAApp/"
373-
$clientPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$currentAppId+"/objectId/"+$currentAppObjectId+"/isMSAApp/"
367+
# Future? $clientPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.Id+"/isMSAApp/"
368+
$clientPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.Id+"/isMSAApp/"
374369

375370
Add-Content -Value "<tr><td>client</td><td>$currentAppId</td><td><a href='$clientPortalUrl'>msal-react-spa</a></td></tr>" -Path createdApps.html
376371
# Declare a list to hold RRA items
@@ -387,21 +382,21 @@ Function ConfigureApplications
387382
# $requiredResourcesAccess.Count
388383
# $requiredResourcesAccess
389384

390-
Update-MgApplication -ApplicationId $currentAppObjectId -RequiredResourceAccess $requiredResourcesAccess
385+
Update-MgApplication -ApplicationId $clientAadApplication.Id -RequiredResourceAccess $requiredResourcesAccess
391386
Write-Host "Granted permissions."
392387

393388

394389

395390
# print the registered app portal URL for any further navigation
396-
Write-Host "Successfully registered and configured that app registration for 'msal-react-spa' at `n $clientPortalUrl" -ForegroundColor Green
391+
Write-Host "Successfully registered and configured that app registration for 'msal-react-spa' at `n $clientPortalUrl" -ForegroundColor Red
397392

398393
# Update config file for 'service'
399-
# $configFile = $pwd.Path + "\..\API\config.js"
400-
$configFile = $(Resolve-Path ($pwd.Path + "\..\API\config.js"))
394+
# $configFile = $pwd.Path + "\..\API\config.json"
395+
$configFile = $(Resolve-Path ($pwd.Path + "\..\API\config.json"))
401396

402397
$dictionary = @{ "Enter_the_Application_Id_Here" = $serviceAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId };
403398

404-
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Yellow
399+
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Green
405400
$dictionary
406401
Write-Host "-----------------"
407402

@@ -413,7 +408,7 @@ Function ConfigureApplications
413408

414409
$dictionary = @{ "Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId;"Enter_the_Web_Api_Application_Id_Here" = $serviceAadApplication.AppId };
415410

416-
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Yellow
411+
Write-Host "Updating the sample config '$configFile' with the following config values:" -ForegroundColor Green
417412
$dictionary
418413
Write-Host "-----------------"
419414

@@ -445,7 +440,7 @@ $ErrorActionPreference = "Stop"
445440

446441
try
447442
{
448-
ConfigureApplications -tenantId $tenantId ls-environment $azureEnvironmentName
443+
ConfigureApplications -tenantId $tenantId -environment $azureEnvironmentName
449444
}
450445
catch
451446
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"Sample": {
3+
"Author": "derisen",
4+
"Title": "Deploy your React Application to Azure Cloud and use Azure services to manage your operations",
5+
"Level": 200,
6+
"Client": "React SPA",
7+
"Service": "Node.js web API",
8+
"RepositoryUrl": "ms-identity-javascript-react-tutorial",
9+
"Endpoint": "AAD v2.0",
10+
"Languages": ["javascript", "nodejs"],
11+
"Description": "This sample demonstrates how to deploy a React single-page application (SPA) coupled with a Node.js web API to Azure Cloud using Azure Storage and Azure App Service, respectively.",
12+
"Products": ["azure-active-directory", "msal-js", "msal-react", "passport-azure-ad"]
13+
},
14+
"AADApps": [
15+
{
16+
"Id": "service",
17+
"Name": "msal-node-api",
18+
"Kind": "WebApi",
19+
"Audience": "AzureADMyOrg",
20+
"Sample": {
21+
"SampleSubPath": "4-Deployment\\1-deploy-storage\\API",
22+
"ProjectDirectory": "\\1-deploy-storage\\API"
23+
},
24+
"Scopes": ["access_as_user"]
25+
},
26+
{
27+
"Id": "client",
28+
"Name": "msal-react-spa",
29+
"Kind": "SinglePageApplication",
30+
"Audience": "AzureADMyOrg",
31+
"HomePage": "https://localhost:3000",
32+
"ReplyUrls": "http://localhost:3000",
33+
"Sample": {
34+
"SampleSubPath": "4-Deployment\\1-deploy-storage\\SPA",
35+
"ProjectDirectory": "\\1-deploy-storage\\SPA"
36+
},
37+
"RequiredResourcesAccess": [
38+
{
39+
"Resource": "service",
40+
"DelegatedPermissions": ["access_as_user"]
41+
}
42+
]
43+
}
44+
],
45+
"CodeConfiguration": [
46+
{
47+
"App": "service",
48+
"SettingKind": "Replace",
49+
"SettingFile": "\\..\\API\\config.json",
50+
"Mappings": [
51+
{
52+
"key": "Enter_the_Application_Id_Here",
53+
"value": ".AppId"
54+
},
55+
{
56+
"key": "Enter_the_Tenant_Info_Here",
57+
"value": "$tenantId"
58+
}
59+
]
60+
},
61+
{
62+
"App": "client",
63+
"SettingKind": "Replace",
64+
"SettingFile": "\\..\\SPA\\src\\authConfig.js",
65+
"Mappings": [
66+
{
67+
"key": "Enter_the_Application_Id_Here",
68+
"value": ".AppId"
69+
},
70+
{
71+
"key": "Enter_the_Tenant_Info_Here",
72+
"value": "$tenantId"
73+
},
74+
{
75+
"key": "Enter_the_Web_Api_Application_Id_Here",
76+
"value": "service.AppId"
77+
}
78+
]
79+
}
80+
]
81+
}

0 commit comments

Comments
 (0)