This repository was archived by the owner on May 17, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 176
.[CmdletBinding()] param( [PSCredential] $Credential, [Parame… #285
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
…atory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')] [string] $tenantId, [Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')] [string] $azureEnvironmentName ) #Requires -Modules AzureAD -RunAsAdministrator <# This script creates the Azure AD applications needed for this sample and updates the configuration files for the visual Studio projects from the data in the Azure AD applications. Before running this script you need to install the AzureAD cmdlets as an administrator. For this: 1) Run Powershell as an administrator 2) in the PowerShell window, type: Install-Module AzureAD There are four ways to run this script. For more information, read the AppCreationScripts.md file in the same folder as this script. #> Function ReplaceInLine([string] $line, [string] $key, [string] $value) { $index = $line.IndexOf($key) if ($index -ige 0) { $index2 = $index+$key.Length $line = $line.Substring(0, $index) + $value + $line.Substring($index2) } return $line } Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary) { $lines = Get-Content $configFilePath $index = 0 while($index -lt $lines.Length) { $line = $lines[$index] foreach($key in $dictionary.Keys) { if ($line.Contains($key)) { $lines[$index] = ReplaceInLine $line $key $dictionary[$key] } } $index++ } Set-Content -Path $configFilePath -Value $lines -Force } Set-Content -Value "<html><body><table>" -Path createdApps.html Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the Azure portal</th></tr></thead><tbody>" -Path createdApps.html $ErrorActionPreference = "Stop" Function ConfigureApplications { <#.Description This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the configuration files in the client and service project of the visual studio solution (App.Config and Web.Config) so that they are consistent with the Applications parameters #> $commonendpoint = "common" if (!$azureEnvironmentName) { $azureEnvironmentName = "AzureCloud" } # $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant # into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD. # Login to Azure PowerShell (interactive if credentials are not already provided: # you'll need to sign-in with creds enabling your to create apps in the tenant) if (!$Credential -and $TenantId) { $creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName } else { if (!$TenantId) { $creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } else { $creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } } if (!$tenantId) { $tenantId = $creds.Tenant.Id } $tenant = Get-AzureADTenantDetail $tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name # Get the user running the script to add the user as the app owner $user = Get-AzureADUser -ObjectId $creds.Account.Id # Create the spa AAD application Write-Host "Creating the AAD application (msal-angular-spa)" # create the application $spaAadApplication = New-AzureADApplication -DisplayName "msal-angular-spa" ` -HomePage "https://amazon.sa" ` -ReplyUrls "https://amazon.sa" ` -IdentifierUris "https://amazon.sa $False # create the service principal of the newly created application $currentAppId = $spaAadApplication.AppId $spaServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp} # add the user running the script as an app owner if needed $owner = Get-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId if ($owner -eq $null) { Add-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId -RefObjectId $user.ObjectId Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($spaServicePrincipal.DisplayName)'" } Write-Host "Done creating the spa application (msal-angular-spa)" # URL of the AAD application in the Azure portal # Future? $spaPortalUrl = "https://amazon.sa#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" $spaPortalUrl = "https://amazon.sa/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" Add-Content -Value "<tr><td>spa</td><td>$currentAppId</td><td><a href='$spaPortalUrl'>msal-angular-spa</a></td></tr>" -Path createdApps.html # Update config file for 'spa' $configFile = $pwd.Path + "\..\SPA\src\app\auth-config.ts" Write-Host "Updating the sample code ($configFile)" $dictionary = @{ "Enter_the_Application_Id_Here" = $spaAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId }; ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary Write-Host "" Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal": Write-Host "- For 'spa'" Write-Host " - Navigate to '$spaPortalUrl'" Write-Host " - Navigate to the Manifest page, find the 'replyUrlsWithType' section and change the type of redirect URI to 'Spa'" -ForegroundColor Red Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html } # Pre-requisites if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) { Install-Module "AzureAD" -Scope CurrentUser } Import-Module AzureAD # Run interactively (will ask you for the tenant ID) ConfigureApplications -Credential $Credential -tenantId $TenantId .[CmdletBinding()] param( [PSCredential] $Credential, [Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')] [string] $tenantId, [Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')] [string] $azureEnvironmentName ) #Requires -Modules AzureAD -RunAsAdministrator <# This script creates the Azure AD applications needed for this sample and updates the configuration files for the visual Studio projects from the data in the Azure AD applications. Before running this script you need to install the AzureAD cmdlets as an administrator. For this: 1) Run Powershell as an administrator 2) in the PowerShell window, type: Install-Module AzureAD There are four ways to run this script. For more information, read the AppCreationScripts.md file in the same folder as this script. #> Function ReplaceInLine([string] $line, [string] $key, [string] $value) { $index = $line.IndexOf($key) if ($index -ige 0) { $index2 = $index+$key.Length $line = $line.Substring(0, $index) + $value + $line.Substring($index2) } return $line } Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary) { $lines = Get-Content $configFilePath $index = 0 while($index -lt $lines.Length) { $line = $lines[$index] foreach($key in $dictionary.Keys) { if ($line.Contains($key)) { $lines[$index] = ReplaceInLine $line $key $dictionary[$key] } } $index++ } Set-Content -Path $configFilePath -Value $lines -Force } Set-Content -Value "<html><body><table>" -Path createdApps.html Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the Azure portal</th></tr></thead><tbody>" -Path createdApps.html $ErrorActionPreference = "Stop" Function ConfigureApplications { <#.Description This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the configuration files in the client and service project of the visual studio solution (App.Config and Web.Config) so that they are consistent with the Applications parameters #> $commonendpoint = "common" if (!$azureEnvironmentName) { $azureEnvironmentName = "AzureCloud" } # $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant # into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD. # Login to Azure PowerShell (interactive if credentials are not already provided: # you'll need to sign-in with creds enabling your to create apps in the tenant) if (!$Credential -and $TenantId) { $creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName } else { if (!$TenantId) { $creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } else { $creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } } if (!$tenantId) { $tenantId = $creds.Tenant.Id } $tenant = Get-AzureADTenantDetail $tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name # Get the user running the script to add the user as the app owner $user = Get-AzureADUser -ObjectId $creds.Account.Id # Create the spa AAD application Write-Host "Creating the AAD application (msal-angular-spa)" # create the application $spaAadApplication = New-AzureADApplication -DisplayName "msal-angular-spa" ` -HomePage "https://amazon.sa" ` -ReplyUrls "https://amazon.sa" ` -IdentifierUris "https://amazon.sa $False # create the service principal of the newly created application $currentAppId = $spaAadApplication.AppId $spaServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp} # add the user running the script as an app owner if needed $owner = Get-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId if ($owner -eq $null) { Add-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId -RefObjectId $user.ObjectId Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($spaServicePrincipal.DisplayName)'" } Write-Host "Done creating the spa application (msal-angular-spa)" # URL of the AAD application in the Azure portal # Future? $spaPortalUrl = "https://amazon.sa#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" $spaPortalUrl = "https://amazon.sa/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" Add-Content -Value "<tr><td>spa</td><td>$currentAppId</td><td><a href='$spaPortalUrl'>msal-angular-spa</a></td></tr>" -Path createdApps.html # Update config file for 'spa' $configFile = $pwd.Path + "\..\SPA\src\app\auth-config.ts" Write-Host "Updating the sample code ($configFile)" $dictionary = @{ "Enter_the_Application_Id_Here" = $spaAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId }; ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary Write-Host "" Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal": Write-Host "- For 'spa'" Write-Host " - Navigate to '$spaPortalUrl'" Write-Host " - Navigate to the Manifest page, find the 'replyUrlsWithType' section and change the type of redirect URI to 'Spa'" -ForegroundColor Red Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html } # Pre-requisites if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) { Install-Module "AzureAD" -Scope CurrentUser } Import-Module AzureAD # Run interactively (will ask you for the tenant ID) ConfigureApplications -Credential $Credential -tenantId $TenantId Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
…ter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')] [string] $tenantId, [Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')] [string] $azureEnvironmentName ) #Requires -Modules AzureAD -RunAsAdministrator <# This script creates the Azure AD applications needed for this sample and updates the configuration files for the visual Studio projects from the data in the Azure AD applications. Before running this script you need to install the AzureAD cmdlets as an administrator. For this: 1) Run Powershell as an administrator 2) in the PowerShell window, type: Install-Module AzureAD There are four ways to run this script. For more information, read the AppCreationScripts.md file in the same folder as this script. #> Function ReplaceInLine([string] $line, [string] $key, [string] $value) { $index = $line.IndexOf($key) if ($index -ige 0) { $index2 = $index+$key.Length $line = $line.Substring(0, $index) + $value + $line.Substring($index2) } return $line } Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary) { $lines = Get-Content $configFilePath $index = 0 while($index -lt $lines.Length) { $line = $lines[$index] foreach($key in $dictionary.Keys) { if ($line.Contains($key)) { $lines[$index] = ReplaceInLine $line $key $dictionary[$key] } } $index++ } Set-Content -Path $configFilePath -Value $lines -Force } Set-Content -Value "
" -Path createdApps.html Add-Content -Value "" -Path createdApps.html $ErrorActionPreference = "Stop" Function ConfigureApplications { <#.Description This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the configuration files in the client and service project of the visual studio solution (App.Config and Web.Config) so that they are consistent with the Applications parameters #> $commonendpoint = "common" if (!$azureEnvironmentName) { $azureEnvironmentName = "AzureCloud" } # $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant # into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD. # Login to Azure PowerShell (interactive if credentials are not already provided: # you'll need to sign-in with creds enabling your to create apps in the tenant) if (!$Credential -and $TenantId) { $creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName } else { if (!$TenantId) { $creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } else { $creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName } } if (!$tenantId) { $tenantId = $creds.Tenant.Id } $tenant = Get-AzureADTenantDetail $tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name # Get the user running the script to add the user as the app owner $user = Get-AzureADUser -ObjectId $creds.Account.Id # Create the spa AAD application Write-Host "Creating the AAD application (msal-angular-spa)" # create the application $spaAadApplication = New-AzureADApplication -DisplayName "msal-angular-spa"-HomePage "https://amazon.sa"-ReplyUrls "https://amazon.sa" ` -IdentifierUris "https://amazon.sa $False # create the service principal of the newly created application $currentAppId = $spaAadApplication.AppId $spaServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp} # add the user running the script as an app owner if needed $owner = Get-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId if ($owner -eq $null) { Add-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId -RefObjectId $user.ObjectId Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($spaServicePrincipal.DisplayName)'" } Write-Host "Done creating the spa application (msal-angular-spa)" # URL of the AAD application in the Azure portal # Future? $spaPortalUrl = "https://amazon.sa#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" $spaPortalUrl = "https://amazon.sa/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/" Add-Content -Value "" -Path createdApps.html # Update config file for 'spa' $configFile = $pwd.Path + "..\SPA\src\app\auth-config.ts" Write-Host "Updating the sample code ($configFile)" $dictionary = @{ "Enter_the_Application_Id_Here" = $spaAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId }; ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary Write-Host "" Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal": Write-Host "- For 'spa'" Write-Host " - Navigate to '$spaPortalUrl'" Write-Host " - Navigate to the Manifest page, find the 'replyUrlsWithType' section and change the type of redirect URI to 'Spa'" -ForegroundColor Red Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------" Add-Content -Value ".[CmdletBinding()]
param(
[PSCredential] $Credential,
[Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
[string] $tenantId,
[Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
[string] $azureEnvironmentName
)
#Requires -Modules AzureAD -RunAsAdministrator
<#
This script creates the Azure AD applications needed for this sample and updates the configuration files
for the visual Studio projects from the data in the Azure AD applications.
Before running this script you need to install the AzureAD cmdlets as an administrator.
For this:
There are four ways to run this script. For more information, read the AppCreationScripts.md file in the same folder as this script.
#>
Function ReplaceInLine([string] $line, [string] $key, [string] $value) {
$index = $line.IndexOf($key)
if ($index -ige 0)
{
$index2 = $index+$key.Length
$line = $line.Substring(0, $index) + $value + $line.Substring($index2)
}
return $line
}
Function ReplaceInTextFile([string] $configFilePath, [System.Collections.HashTable] $dictionary) {
$lines = Get-Content $configFilePath
$index = 0
while($index -lt $lines.Length)
{
$line = $lines[$index]
foreach($key in $dictionary.Keys)
{
if ($line.Contains($key))
{
$lines[$index] = ReplaceInLine $line $key $dictionary[$key]
}
}
$index++
}
}
Set-Content -Value "
" -Path createdApps.html Add-Content -Value "" -Path createdApps.html$ErrorActionPreference = "Stop"
Function ConfigureApplications
{
<#.Description
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
so that they are consistent with the Applications parameters
#>
$commonendpoint = "common"
Create the spa AAD application
Write-Host "Creating the AAD application (msal-angular-spa)"
create the application
$spaAadApplication = New-AzureADApplication -DisplayName "msal-angular-spa"
-HomePage "https://amazon.sa"-ReplyUrls "https://amazon.sa" `
-IdentifierUris "https://amazon.sa $False
create the service principal of the newly created application
$currentAppId = $spaAadApplication.AppId
$spaServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
add the user running the script as an app owner if needed
$owner = Get-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId$user.UserPrincipalName)' added as an application owner to app '$ ($spaServicePrincipal.DisplayName)'"
if ($owner -eq $null)
{
Add-AzureADApplicationOwner -ObjectId $spaAadApplication.ObjectId -RefObjectId $user.ObjectId
Write-Host "'$(
}
Write-Host "Done creating the spa application (msal-angular-spa)"
URL of the AAD application in the Azure portal
Future? $spaPortalUrl = "https://amazon.sa#@"+$tenantName+"/blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/"
$spaPortalUrl = "https://amazon.sa/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/CallAnAPI/appId/"+$spaAadApplication.AppId+"/objectId/"+$spaAadApplication.ObjectId+"/isMSAApp/"
" -Path createdApps.htmlAdd-Content -Value "
Update config file for 'spa'
$configFile = $pwd.Path + "..\SPA\src\app\auth-config.ts"
Write-Host "Updating the sample code ($configFile)"
$dictionary = @{ "Enter_the_Application_Id_Here" = $spaAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId };
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
Write-Host ""
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal":
Write-Host "- For 'spa'"
Write-Host " - Navigate to '$spaPortalUrl'"
Write-Host " - Navigate to the Manifest page, find the 'replyUrlsWithType' section and change the type of redirect URI to 'Spa'" -ForegroundColor Red
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
Add-Content -Value "
}
Pre-requisites
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
Install-Module "AzureAD" -Scope CurrentUser
}
Import-Module AzureAD
Run interactively (will ask you for the tenant ID) ConfigureApplications -Credential $Credential -tenantId $TenantId
Purpose
Does this introduce a breaking change?
Pull Request Type
What kind of change does this Pull Request introduce?
How to Test
What to Check
Verify that the following are valid
Other Information