Skip to content

Commit 016a1f8

Browse files
authored
Merge pull request #7 from Azure-Samples/app_creation_scripts
Updating AppCreation scripts
2 parents 6b7cb85 + b411113 commit 016a1f8

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

AppCreationScripts/Cleanup.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
99
Install-Module "AzureAD" -Scope CurrentUser
1010
}
1111
Import-Module AzureAD
12-
$ErrorActionPreference = 'Stop'
12+
$ErrorActionPreference = "Stop"
1313

1414
Function Cleanup
1515
{

AppCreationScripts/Configure.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Function AddResourcePermission($requiredAccess, `
6565
}
6666

6767
#
68-
# Exemple: GetRequiredPermissions "Microsoft Graph" "Graph.Read|User.Read"
68+
# Example: GetRequiredPermissions "Microsoft Graph" "Graph.Read|User.Read"
6969
# See also: http://stackoverflow.com/questions/42164581/how-to-configure-a-new-azure-ad-application-through-powershell
7070
Function GetRequiredPermissions([string] $applicationDisplayName, [string] $requiredDelegatedPermissions, [string]$requiredApplicationPermissions, $servicePrincipal)
7171
{
@@ -129,18 +129,18 @@ Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTab
129129
Set-Content -Path $configFilePath -Value $lines -Force
130130
}
131131

132-
133132
Set-Content -Value "<html><body><table>" -Path createdApps.html
134133
Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the Azure portal</th></tr></thead><tbody>" -Path createdApps.html
135134

135+
$ErrorActionPreference = "Stop"
136+
136137
Function ConfigureApplications
137138
{
138139
<#.Description
139140
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
140141
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
141142
so that they are consistent with the Applications parameters
142143
#>
143-
144144
$commonendpoint = "common"
145145

146146
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
@@ -172,7 +172,7 @@ Function ConfigureApplications
172172
$tenant = Get-AzureADTenantDetail
173173
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
174174

175-
# Get the user running the script
175+
# Get the user running the script to add the user as the app owner
176176
$user = Get-AzureADUser -ObjectId $creds.Account.Id
177177

178178
# Create the pythonwebapp AAD application
@@ -182,15 +182,16 @@ Function ConfigureApplications
182182
$fromDate = [DateTime]::Now;
183183
$key = CreateAppKey -fromDate $fromDate -durationInYears 2 -pw $pw
184184
$pythonwebappAppKey = $pw
185+
# create the application
185186
$pythonwebappAadApplication = New-AzureADApplication -DisplayName "python-webapp" `
186-
-LogoutUrl "http://localhost:5000/logout" `
187187
-ReplyUrls "http://localhost:5000/getAToken" `
188188
-IdentifierUris "https://$tenantName/python-webapp" `
189189
-AvailableToOtherTenants $True `
190190
-PasswordCredentials $key `
191191
-Oauth2AllowImplicitFlow $true `
192192
-PublicClient $False
193193

194+
# create the service principal of the newly created application
194195
$currentAppId = $pythonwebappAadApplication.AppId
195196
$pythonwebappServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
196197

@@ -215,7 +216,7 @@ Function ConfigureApplications
215216
# Add Required Resources Access (from 'pythonwebapp' to 'Microsoft Graph')
216217
Write-Host "Getting access from 'pythonwebapp' to 'Microsoft Graph'"
217218
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
218-
-requiredDelegatedPermissions "User.Read" `
219+
-requiredDelegatedPermissions "User.ReadBasic.All" `
219220

220221
$requiredResourcesAccess.Add($requiredPermissions)
221222

@@ -235,7 +236,8 @@ Function ConfigureApplications
235236
# Pre-requisites
236237
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
237238
Install-Module "AzureAD" -Scope CurrentUser
238-
}
239+
}
240+
239241
Import-Module AzureAD
240242

241243
# Run interactively (will ask you for the tenant ID)

AppCreationScripts/sample.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
{
2323
"Resource": "Microsoft Graph",
2424
"DelegatedPermissions": [
25-
"User.Read"
25+
"User.ReadBasic.All"
2626
]
2727
}
2828
],
29-
"ReplyUrls": "http://localhost:5000/getAToken",
30-
"LogoutUrl": "http://localhost:5000/logout"
29+
"ReplyUrls": "http://localhost:5000/getAToken"
3130
}
3231
],
3332

0 commit comments

Comments
 (0)