@@ -85,6 +85,40 @@ Function GetRequiredPermissions([string] $applicationDisplayName, [string] $requ
85
85
}
86
86
87
87
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
+
88
122
Function ConfigureApplications
89
123
{
90
124
$isOpenSSl = ' N' # temporary disable open certificate creation
@@ -112,14 +146,14 @@ Function ConfigureApplications
112
146
113
147
114
148
# Create the webApp AAD application
115
- Write-Host " Creating the AAD application (WebApp )"
149
+ Write-Host " Creating the AAD application (Azure_Api_WebApp )"
116
150
# Get a 6 months application key for the webApp Application
117
151
$fromDate = [DateTime ]::Now;
118
152
$key = CreateAppKey - fromDate $fromDate - durationInMonths 6
119
153
120
154
121
155
# create the application
122
- $webAppAadApplication = New-MgApplication - DisplayName " WebApp " `
156
+ $webAppAadApplication = New-MgApplication - DisplayName " Azure_Api_WebApp " `
123
157
- Web `
124
158
@ { `
125
159
RedirectUris = " https://localhost:44321/" , " https://localhost:44321/signin-oidc" ; `
@@ -133,7 +167,7 @@ Function ConfigureApplications
133
167
$webAppAppKey = $pwdCredential.SecretText
134
168
135
169
$tenantName = (Get-MgApplication - ApplicationId $webAppAadApplication.Id ).PublisherDomain
136
- Update-MgApplication - ApplicationId $webAppAadApplication.Id - IdentifierUris @ (" https://$tenantName /WebApp " )
170
+ Update-MgApplication - ApplicationId $webAppAadApplication.Id - IdentifierUris @ (" https://$tenantName /Azure_Api_WebApp " )
137
171
138
172
# create the service principal of the newly created application
139
173
$currentAppId = $webAppAadApplication.AppId
@@ -146,35 +180,40 @@ Function ConfigureApplications
146
180
New-MgApplicationOwnerByRef - ApplicationId $webAppAadApplication.Id - BodyParameter = @ {" @odata.id" = " htps://graph.microsoft.com/v1.0/directoryObjects/$user .ObjectId" }
147
181
Write-Host " '$ ( $user.UserPrincipalName ) ' added as an application owner to app '$ ( $webAppServicePrincipal.DisplayName ) '"
148
182
}
149
- Write-Host " Done creating the webApp application (WebApp )"
183
+ Write-Host " Done creating the webApp application (Azure_Api_WebApp )"
150
184
151
185
# URL of the AAD application in the Azure portal
152
186
# Future? $webAppPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$webAppAadApplication.AppId+"/objectId/"+$webAppAadApplication.Id+"/isMSAApp/"
153
187
$webAppPortalUrl = " https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/" + $webAppAadApplication.AppId + " /objectId/" + $webAppAadApplication.Id + " /isMSAApp/"
154
- Add-Content - Value " <tr><td>webApp</td><td>$currentAppId </td><td><a href='$webAppPortalUrl '>WebApp </a></td></tr>" - Path createdApps.html
188
+ Add-Content - Value " <tr><td>webApp</td><td>$currentAppId </td><td><a href='$webAppPortalUrl '>Azure_Api_WebApp </a></td></tr>" - Path createdApps.html
155
189
$requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphRequiredResourceAccess ]
156
190
157
191
# Add Required Resources Access (from 'webApp' to 'Microsoft Graph')
158
192
Write-Host " Getting access from 'webApp' to 'Microsoft Graph'"
159
- $requiredPermissions = GetRequiredPermissions - applicationDisplayName " Microsoft Graph" `
193
+ $requiredPermission = GetRequiredPermissions - applicationDisplayName " Microsoft Graph" `
160
194
- requiredDelegatedPermissions " User.Read" `
161
- $requiredResourcesAccess.Add ($requiredPermissions )
195
+
196
+ $requiredResourcesAccess.Add ($requiredPermission )
162
197
163
198
# Add Required Resources Access (from 'webApp' to 'Windows Azure Service Management API')
164
199
Write-Host " Getting access from 'webApp' to 'Windows Azure Service Management API'"
165
- $requiredPermissions = GetRequiredPermissions - applicationDisplayName " Windows Azure Service Management API" `
200
+ $requiredPermission = GetRequiredPermissions - applicationDisplayName " Windows Azure Service Management API" `
166
201
- requiredDelegatedPermissions " user_impersonation" `
167
- $requiredResourcesAccess.Add ($requiredPermissions )
202
+
203
+ $requiredResourcesAccess.Add ($requiredPermission )
168
204
169
205
# Add Required Resources Access (from 'webApp' to 'Azure Storage')
170
206
Write-Host " Getting access from 'webApp' to 'Azure Storage'"
171
- $requiredPermissions = GetRequiredPermissions - applicationDisplayName " Azure Storage" `
207
+ $requiredPermission = GetRequiredPermissions - applicationDisplayName " Azure Storage" `
172
208
- requiredDelegatedPermissions " user_impersonation" `
173
- $requiredResourcesAccess.Add ($requiredPermissions )
209
+
210
+ $requiredResourcesAccess.Add ($requiredPermission )
174
211
Update-MgApplication - ApplicationId $webAppAadApplication.Id - RequiredResourceAccess $requiredResourcesAccess
175
212
Write-Host " Granted permissions."
176
213
177
- Write-Host " Successfully registered and configured that app registration for 'WebApp' at" - ForegroundColor Green
214
+ Write-Host " Successfully registered and configured that app registration for 'Azure_Api_WebApp' at" - ForegroundColor Green
215
+
216
+ # print the registered app portal URL for any further navigation
178
217
$webAppPortalUrl
179
218
180
219
# Update config file for 'webApp'
@@ -186,6 +225,7 @@ Function ConfigureApplications
186
225
Write-Host " Updating the sample config '$configFile ' with the following config values"
187
226
$dictionary
188
227
228
+ UpdateTextFile - configFilePath $configFile - dictionary $dictionary
189
229
if ($isOpenSSL -eq ' Y' )
190
230
{
191
231
Write-Host - ForegroundColor Green " ------------------------------------------------------------------------------------------------"
0 commit comments