Skip to content

Commit 4b88455

Browse files
author
Kalyan Krishna
committed
updated and bugs fixed
1 parent 7992525 commit 4b88455

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

2-WebApp-graph-user/2-3-Multi-Tenant/AppCreationScripts/Cleanup.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ Function Cleanup
3838
Write-Host "Removing 'webApp' (WebApp-MultiTenant-v2) if needed"
3939
try
4040
{
41-
Get-MgApplication -Filter "DisplayName eq 'WebApp-MultiTenant-v2'" | ForEach-Object {Remove-MgApplication -ApplicationId $_.Id }
41+
Get-MgApplication -Filter "DisplayName eq 'WebApp-MultiTenant-v2'" | ForEach-Object {Remove-MgApplication -ApplicationId $_.Id }
4242
}
4343
catch
4444
{
45-
Write-Host "Unable to remove the application 'WebApp-MultiTenant-v2' . Try deleting manually." -ForegroundColor White -BackgroundColor Red
45+
$message = $_
46+
Write-Warning $Error[0]
47+
Write-Host "Unable to remove the application 'WebApp-MultiTenant-v2'. Error is $message. Try deleting manually." -ForegroundColor White -BackgroundColor Red
4648
}
4749

4850
Write-Host "Making sure there are no more (WebApp-MultiTenant-v2) applications found, will remove if needed..."
49-
$apps = Get-MgApplication -Filter "DisplayName eq 'WebApp-MultiTenant-v2'"
51+
$apps = Get-MgApplication -Filter "DisplayName eq 'WebApp-MultiTenant-v2'" | Format-List Id, DisplayName, AppId, SignInAudience, PublisherDomain
5052

5153
if ($apps)
5254
{
@@ -55,18 +57,20 @@ Function Cleanup
5557

5658
foreach ($app in $apps)
5759
{
58-
Remove-MgApplication -ApplicationId $app.Id
60+
Remove-MgApplication -ApplicationId $app.Id -Debug
5961
Write-Host "Removed WebApp-MultiTenant-v2.."
6062
}
6163

6264
# also remove service principals of this app
6365
try
6466
{
65-
Get-MgServicePrincipal -filter "DisplayName eq 'WebApp-MultiTenant-v2'" | ForEach-Object {Remove-MgServicePrincipal -ApplicationId $_.Id -Confirm:$false}
67+
Get-MgServicePrincipal -filter "DisplayName eq 'WebApp-MultiTenant-v2'" | ForEach-Object {Remove-MgServicePrincipal -ServicePrincipalId $_.Id -Confirm:$false}
6668
}
6769
catch
6870
{
69-
Write-Host "Unable to remove ServicePrincipal 'WebApp-MultiTenant-v2' . Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
71+
$message = $_
72+
Write-Warning $Error[0]
73+
Write-Host "Unable to remove ServicePrincipal 'WebApp-MultiTenant-v2'. Error is $message. Try deleting manually from Enterprise applications." -ForegroundColor White -BackgroundColor Red
7074
}
7175
}
7276

2-WebApp-graph-user/2-3-Multi-Tenant/AppCreationScripts/Configure.ps1

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,40 @@ Function GetRequiredPermissions([string] $applicationDisplayName, [string] $requ
8585
}
8686

8787

88+
Function UpdateLine([string] $line, [string] $value)
89+
{
90+
$index = $line.IndexOf(':')
91+
$lineEnd = ''
92+
93+
if($line[$line.Length - 1] -eq ','){ $lineEnd = ',' }
94+
95+
if ($index -ige 0)
96+
{
97+
$line = $line.Substring(0, $index+1) + " " + '"' + $value+ '"' + $lineEnd
98+
}
99+
return $line
100+
}
101+
102+
Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary)
103+
{
104+
$lines = Get-Content $configFilePath
105+
$index = 0
106+
while($index -lt $lines.Length)
107+
{
108+
$line = $lines[$index]
109+
foreach($key in $dictionary.Keys)
110+
{
111+
if ($line.Contains($key))
112+
{
113+
$lines[$index] = UpdateLine $line $dictionary[$key]
114+
}
115+
}
116+
$index++
117+
}
118+
119+
Set-Content -Path $configFilePath -Value $lines -Force
120+
}
121+
88122
Function ConfigureApplications
89123
{
90124
$isOpenSSl = 'N' #temporary disable open certificate creation
@@ -165,11 +199,15 @@ Function ConfigureApplications
165199
Write-Host "Granted permissions."
166200

167201
# Update config file for 'webApp'
168-
$configFile = $pwd.Path + "\..\appsettings.json"
202+
# $configFile = $pwd.Path + "\..\appsettings.json"
203+
$configFile = $(Resolve-Path ($pwd.Path + "\..\appsettings.json"))
204+
169205
$dictionary = @{ "ClientId" = $webAppAadApplication.AppId;"TenantId" = 'organizations';"Domain" = $tenantName;"ClientSecret" = $webAppAppKey };
170206

171-
Write-Host "Updating the sample code ($configFile)"
207+
Write-Host "Updating the sample code ($configFile) with the following config values"
208+
$dictionary
172209

210+
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
173211
if($isOpenSSL -eq 'Y')
174212
{
175213
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
@@ -193,7 +231,16 @@ Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the
193231
$ErrorActionPreference = "Stop"
194232

195233
# Run interactively (will ask you for the tenant ID)
196-
ConfigureApplications -tenantId $tenantId -environment $azureEnvironmentName
197234

235+
try
236+
{
237+
ConfigureApplications -tenantId $tenantId -environment $azureEnvironmentName
238+
}
239+
catch
240+
{
241+
$message = $_
242+
Write-Warning $Error[0]
243+
Write-Host "Unable to register apps. Error is $message." -ForegroundColor White -BackgroundColor Red
244+
}
198245
Write-Host "Disconnecting from tenant"
199246
Disconnect-MgGraph

2-WebApp-graph-user/2-3-Multi-Tenant/AppCreationScripts/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"CodeConfiguration": [
4545
{
4646
"App": "webApp",
47-
"SettingKind": "JSon",
47+
"SettingKind": "JSON",
4848
"SettingFile": "\\..\\appsettings.json",
4949
"Mappings": [
5050
{

0 commit comments

Comments
 (0)