" -Path createdApps.html
106 |
107 | Function ConfigureApplications
108 | {
109 | <#.Description
110 | This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
111 | configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
112 | so that they are consistent with the Applications parameters
113 | #>
114 | [CmdletBinding()]
115 | param(
116 | [PSCredential] $Credential,
117 | [Parameter(HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
118 | [string] $tenantId
119 | )
120 |
121 | process
122 | {
123 | # $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
124 | # into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
125 |
126 | # Login to Azure PowerShell (interactive if credentials are not already provided:
127 | # you'll need to sign-in with creds enabling your to create apps in the tenant)
128 | if (!$Credential -and $TenantId)
129 | {
130 | $creds = Connect-AzureAD -TenantId $tenantId
131 | }
132 | else
133 | {
134 | if (!$TenantId)
135 | {
136 | $creds = Connect-AzureAD -Credential $Credential
137 | }
138 | else
139 | {
140 | $creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
141 | }
142 | }
143 |
144 | if (!$tenantId)
145 | {
146 | $tenantId = $creds.Tenant.Id
147 | }
148 | $tenant = Get-AzureADTenantDetail
149 | $tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
150 |
151 | # Create the app AAD application
152 | Write-Host "Creating the AAD appplication (Native-Headless-Application)"
153 | $appAadApplication = New-AzureADApplication -DisplayName "Native-Headless-Application" `
154 | -ReplyUrls "https://Native-Headless-Application" `
155 | -PublicClient $True
156 |
157 |
158 | $currentAppId = $appAadApplication.AppId
159 | $appServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
160 | Write-Host "Done."
161 |
162 | # URL of the AAD application in the Azure portal
163 | $appPortalUrl = "https://portal.azure.com/#@"+$tenantName+"/blade/Microsoft_AAD_IAM/ApplicationBlade/appId/"+$appAadApplication.AppId+"/objectId/"+$appAadApplication.ObjectId
164 | Add-Content -Value "app | $currentAppId | Native-Headless-Application |
" -Path createdApps.html
165 |
166 | $requiredResourcesAccess = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.RequiredResourceAccess]
167 | # Add Required Resources Access (from 'app' to 'Microsoft Graph')
168 | Write-Host "Getting access from 'app' to 'Microsoft Graph'"
169 | $requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
170 | -requiredDelegatedPermissions "User.Read";
171 | $requiredResourcesAccess.Add($requiredPermissions)
172 | Set-AzureADApplication -ObjectId $appAadApplication.ObjectId -RequiredResourceAccess $requiredResourcesAccess
173 | Write-Host "Granted."
174 |
175 | # Update config file for 'app'
176 | $configFile = $pwd.Path + "\..\src\main\java\UsernamePasswordFlow.java"
177 | Write-Host "Updating the sample code ($configFile)"
178 | $dictionary = @{ "private final static String APP_ID" = $appAadApplication.AppId };
179 | UpdateTextFile -configFilePath $configFile -dictionary $dictionary
180 | Write-Host ""
181 | Write-Host "IMPORTANT: Think of completing the following manual step(s) in the Azure portal":
182 | Write-Host "- For 'app'"
183 | Write-Host " - Navigate to '$appPortalUrl'"
184 | Write-Host " - click Settings > Required permissions > Grant Permissions"
185 | Add-Content -Value "