Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 98f7473

Browse files
author
Tiago Brenck
committed
AppCreationScripts testing
1 parent 99283da commit 98f7473

File tree

4 files changed

+147
-152
lines changed

4 files changed

+147
-152
lines changed

AppCreationScripts/Cleanup.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ This function removes the Azure AD applications for the sample. These applicatio
4949
# Removes the applications
5050
Write-Host "Cleaning-up applications from tenant '$tenantName'"
5151

52-
Write-Host "Removing 'java_webapp' (java_webapp) if needed"
53-
Get-AzureADApplication -Filter "DisplayName eq 'java_webapp'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
54-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'java_webapp'"
52+
Write-Host "Removing 'service' (java_obo) if needed"
53+
Get-AzureADApplication -Filter "DisplayName eq 'java_obo'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
54+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'java_obo'"
5555
if ($apps)
5656
{
5757
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -60,14 +60,14 @@ This function removes the Azure AD applications for the sample. These applicatio
6060
foreach ($app in $apps)
6161
{
6262
Remove-AzureADApplication -ObjectId $app.ObjectId
63-
Write-Host "Removed java_webapp.."
63+
Write-Host "Removed java_obo.."
6464
}
6565
# also remove service principals of this app
66-
Get-AzureADServicePrincipal -filter "DisplayName eq 'java_webapp'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
66+
Get-AzureADServicePrincipal -filter "DisplayName eq 'java_obo'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
6767

68-
Write-Host "Removing 'java_obo' (java_obo) if needed"
69-
Get-AzureADApplication -Filter "DisplayName eq 'java_obo'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
70-
$apps = Get-AzureADApplication -Filter "DisplayName eq 'java_obo'"
68+
Write-Host "Removing 'client' (java_webapp) if needed"
69+
Get-AzureADApplication -Filter "DisplayName eq 'java_webapp'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
70+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'java_webapp'"
7171
if ($apps)
7272
{
7373
Remove-AzureADApplication -ObjectId $apps.ObjectId
@@ -76,10 +76,10 @@ This function removes the Azure AD applications for the sample. These applicatio
7676
foreach ($app in $apps)
7777
{
7878
Remove-AzureADApplication -ObjectId $app.ObjectId
79-
Write-Host "Removed java_obo.."
79+
Write-Host "Removed java_webapp.."
8080
}
8181
# also remove service principals of this app
82-
Get-AzureADServicePrincipal -filter "DisplayName eq 'java_obo'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
82+
Get-AzureADServicePrincipal -filter "DisplayName eq 'java_webapp'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
8383

8484
}
8585

AppCreationScripts/Configure.ps1

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -216,81 +216,31 @@ Function ConfigureApplications
216216
# Get the user running the script to add the user as the app owner
217217
$user = Get-AzureADUser -ObjectId $creds.Account.Id
218218

219-
# Create the java_webapp AAD application
220-
Write-Host "Creating the AAD application (java_webapp)"
221-
# Get a 2 years application key for the java_webapp Application
222-
$pw = ComputePassword
223-
$fromDate = [DateTime]::Now;
224-
$key = CreateAppKey -fromDate $fromDate -durationInYears 2 -pw $pw
225-
$java_webappAppKey = $pw
226-
# create the application
227-
$java_webappAadApplication = New-AzureADApplication -DisplayName "java_webapp" `
228-
-LogoutUrl "https://localhost:8080/msal4jsample/sign-out" `
229-
-ReplyUrls "https://localhost:8080/msal4jsample/secure/aad", "https://localhost:8080/msal4jsample/graph/me" `
230-
-IdentifierUris "https://$tenantName/java_webapp" `
231-
-AvailableToOtherTenants $True `
232-
-PasswordCredentials $key `
233-
-Oauth2AllowImplicitFlow $true `
234-
-PublicClient $False
235-
236-
# create the service principal of the newly created application
237-
$currentAppId = $java_webappAadApplication.AppId
238-
$java_webappServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
239-
240-
# add the user running the script as an app owner if needed
241-
$owner = Get-AzureADApplicationOwner -ObjectId $java_webappAadApplication.ObjectId
242-
if ($owner -eq $null)
243-
{
244-
Add-AzureADApplicationOwner -ObjectId $java_webappAadApplication.ObjectId -RefObjectId $user.ObjectId
245-
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($java_webappServicePrincipal.DisplayName)'"
246-
}
247-
248-
249-
Write-Host "Done creating the java_webapp application (java_webapp)"
250-
251-
# URL of the AAD application in the Azure portal
252-
# Future? $java_webappPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$java_webappAadApplication.AppId+"/objectId/"+$java_webappAadApplication.ObjectId+"/isMSAApp/"
253-
$java_webappPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$java_webappAadApplication.AppId+"/objectId/"+$java_webappAadApplication.ObjectId+"/isMSAApp/"
254-
Add-Content -Value "<tr><td>java_webapp</td><td>$currentAppId</td><td><a href='$java_webappPortalUrl'>java_webapp</a></td></tr>" -Path createdApps.html
255-
256-
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
257-
258-
# Add Required Resources Access (from 'java_webapp' to 'service')
259-
Write-Host "Getting access from 'java_webapp' to 'service'"
260-
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "service" `
261-
-requiredDelegatedPermissions "User.Read|access_as_user" `
262-
263-
$requiredResourcesAccess.Add($requiredPermissions)
264-
265-
266-
Set-AzureADApplication -ObjectId $java_webappAadApplication.ObjectId -RequiredResourceAccess $requiredResourcesAccess
267-
Write-Host "Granted permissions."
268-
269-
# Create the java_obo AAD application
219+
# Create the service AAD application
270220
Write-Host "Creating the AAD application (java_obo)"
271-
# Get a 2 years application key for the java_obo Application
221+
# Get a 2 years application key for the service Application
272222
$pw = ComputePassword
273223
$fromDate = [DateTime]::Now;
274224
$key = CreateAppKey -fromDate $fromDate -durationInYears 2 -pw $pw
275-
$java_oboAppKey = $pw
225+
$serviceAppKey = $pw
276226
# create the application
277-
$java_oboAadApplication = New-AzureADApplication -DisplayName "java_obo" `
278-
-AvailableToOtherTenants $True `
279-
-PasswordCredentials $key `
280-
-PublicClient $False
281-
$java_oboIdentifierUri = 'api://'+$java_oboAadApplication.AppId
282-
Set-AzureADApplication -ObjectId $java_oboAadApplication.ObjectId -IdentifierUris $java_oboIdentifierUri
227+
$serviceAadApplication = New-AzureADApplication -DisplayName "java_obo" `
228+
-AvailableToOtherTenants $True `
229+
-PasswordCredentials $key `
230+
-PublicClient $False
231+
$serviceIdentifierUri = 'api://'+$serviceAadApplication.AppId
232+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -IdentifierUris $serviceIdentifierUri
283233

284234
# create the service principal of the newly created application
285-
$currentAppId = $java_oboAadApplication.AppId
286-
$java_oboServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
235+
$currentAppId = $serviceAadApplication.AppId
236+
$serviceServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
287237

288238
# add the user running the script as an app owner if needed
289-
$owner = Get-AzureADApplicationOwner -ObjectId $java_oboAadApplication.ObjectId
239+
$owner = Get-AzureADApplicationOwner -ObjectId $serviceAadApplication.ObjectId
290240
if ($owner -eq $null)
291241
{
292-
Add-AzureADApplicationOwner -ObjectId $java_oboAadApplication.ObjectId -RefObjectId $user.ObjectId
293-
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($java_oboServicePrincipal.DisplayName)'"
242+
Add-AzureADApplicationOwner -ObjectId $serviceAadApplication.ObjectId -RefObjectId $user.ObjectId
243+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($serviceServicePrincipal.DisplayName)'"
294244
}
295245

296246
# rename the user_impersonation scope if it exists to match the readme steps or add a new scope
@@ -323,31 +273,83 @@ Function ConfigureApplications
323273
# add/update scopes
324274
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -OAuth2Permission $scopes
325275

326-
Write-Host "Done creating the java_obo application (java_obo)"
276+
Write-Host "Done creating the service application (java_obo)"
327277

328278
# URL of the AAD application in the Azure portal
329-
# Future? $java_oboPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$java_oboAadApplication.AppId+"/objectId/"+$java_oboAadApplication.ObjectId+"/isMSAApp/"
330-
$java_oboPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$java_oboAadApplication.AppId+"/objectId/"+$java_oboAadApplication.ObjectId+"/isMSAApp/"
331-
Add-Content -Value "<tr><td>java_obo</td><td>$currentAppId</td><td><a href='$java_oboPortalUrl'>java_obo</a></td></tr>" -Path createdApps.html
279+
# Future? $servicePortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.ObjectId+"/isMSAApp/"
280+
$servicePortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$serviceAadApplication.AppId+"/objectId/"+$serviceAadApplication.ObjectId+"/isMSAApp/"
281+
Add-Content -Value "<tr><td>service</td><td>$currentAppId</td><td><a href='$servicePortalUrl'>java_obo</a></td></tr>" -Path createdApps.html
332282

333283
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
334284

335-
# Add Required Resources Access (from 'java_obo' to 'Microsoft Graph')
336-
Write-Host "Getting access from 'java_obo' to 'Microsoft Graph'"
285+
# Add Required Resources Access (from 'service' to 'Microsoft Graph')
286+
Write-Host "Getting access from 'service' to 'Microsoft Graph'"
337287
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
338288
-requiredDelegatedPermissions "User.Read" `
339289

340290
$requiredResourcesAccess.Add($requiredPermissions)
341291

342292

343-
Set-AzureADApplication -ObjectId $java_oboAadApplication.ObjectId -RequiredResourceAccess $requiredResourcesAccess
293+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -RequiredResourceAccess $requiredResourcesAccess
344294
Write-Host "Granted permissions."
345295

346-
# Update config file for 'webApp'
347-
$configFile = $pwd.Path + "\..\appsettings.json"
348-
Write-Host "Updating the sample code ($configFile)"
349-
$dictionary = @{ "ClientId" = $webAppAadApplication.AppId;"TenantId" = $tenantId;"Domain" = $tenantName };
350-
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
296+
# Create the client AAD application
297+
Write-Host "Creating the AAD application (java_webapp)"
298+
# Get a 2 years application key for the client Application
299+
$pw = ComputePassword
300+
$fromDate = [DateTime]::Now;
301+
$key = CreateAppKey -fromDate $fromDate -durationInYears 2 -pw $pw
302+
$clientAppKey = $pw
303+
# create the application
304+
$clientAadApplication = New-AzureADApplication -DisplayName "java_webapp" `
305+
-LogoutUrl "https://localhost:8080/msal4jsample/sign-out" `
306+
-ReplyUrls "https://localhost:8080/msal4jsample/secure/aad" `
307+
-IdentifierUris "https://$tenantName/java_webapp" `
308+
-AvailableToOtherTenants $True `
309+
-PasswordCredentials $key `
310+
-Oauth2AllowImplicitFlow $true `
311+
-PublicClient $False
312+
313+
# create the service principal of the newly created application
314+
$currentAppId = $clientAadApplication.AppId
315+
$clientServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
316+
317+
# add the user running the script as an app owner if needed
318+
$owner = Get-AzureADApplicationOwner -ObjectId $clientAadApplication.ObjectId
319+
if ($owner -eq $null)
320+
{
321+
Add-AzureADApplicationOwner -ObjectId $clientAadApplication.ObjectId -RefObjectId $user.ObjectId
322+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
323+
}
324+
325+
326+
Write-Host "Done creating the client application (java_webapp)"
327+
328+
# URL of the AAD application in the Azure portal
329+
# Future? $clientPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.ObjectId+"/isMSAApp/"
330+
$clientPortalUrl = "https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$clientAadApplication.AppId+"/objectId/"+$clientAadApplication.ObjectId+"/isMSAApp/"
331+
Add-Content -Value "<tr><td>client</td><td>$currentAppId</td><td><a href='$clientPortalUrl'>java_webapp</a></td></tr>" -Path createdApps.html
332+
333+
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
334+
335+
# Add Required Resources Access (from 'client' to 'service')
336+
Write-Host "Getting access from 'client' to 'service'"
337+
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "java_obo" `
338+
-requiredDelegatedPermissions "access_as_user" `
339+
340+
$requiredResourcesAccess.Add($requiredPermissions)
341+
342+
343+
Set-AzureADApplication -ObjectId $clientAadApplication.ObjectId -RequiredResourceAccess $requiredResourcesAccess
344+
Write-Host "Granted permissions."
345+
346+
# Configure known client applications for service
347+
Write-Host "Configure known client applications for the 'service'"
348+
$knowApplications = New-Object System.Collections.Generic.List[System.String]
349+
$knowApplications.Add($clientAadApplication.AppId)
350+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -KnownClientApplications $knowApplications
351+
Write-Host "Configured."
352+
351353

352354
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
353355
}

0 commit comments

Comments
 (0)