Skip to content

Commit

Permalink
Updates to CLI calls to create/update azure ad app (#363)
Browse files Browse the repository at this point in the history
* Updates to CLI calls to create/update azure ad app

* Removed guid generation

Co-authored-by: Alex Clark <[email protected]>
  • Loading branch information
alexc-MSFT and Alex Clark committed Jun 8, 2022
1 parent 23a91d1 commit 77aca75
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions Deployment/Scripts/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,22 @@ function InstallModules ($modules) {
if ($spModule) {
throw('Please remove the older "SharePointPnPPowerShellOnline" module before the deployment can install the new cross-platform module "PnP.PowerShell"')
}
else {
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false -MaximumVersion 1.9.0
}
}

try {
Write-Host('Installing required PowerShell Module {0}' -f $module) -ForegroundColor Yellow
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false
else {
try {
Write-Host('Installing required PowerShell Module {0}' -f $module) -ForegroundColor Yellow
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false
}
catch {
throw('Failed to install PowerShell module {0}: {1}' -f $module, $_.Exception.Message)
}
}
catch {
throw('Failed to install PowerShell module {0}: {1}' -f $module, $_.Exception.Message)
}

}

}

if ($psTrustDisabled) {
Expand Down Expand Up @@ -527,7 +533,9 @@ function CreateAzureADApp {
# Update azure ad app registration using CLI
Write-Host "Azure AD App '$appName' already exists - updating existing app..." -ForegroundColor Yellow

az ad app update --id $app.appId --required-resource-accesses './manifest.json' --password $global:appSecret
az ad app update --id $app.appId --required-resource-accesses './manifest.json'

$global:appId = $app.appId

Write-Host "Waiting for app to finish updating..."

Expand All @@ -541,7 +549,11 @@ function CreateAzureADApp {
Write-Host "Creating Azure AD App - '$appName'..." -ForegroundColor Yellow

# Create azure ad app registration using CLI
az ad app create --display-name $appName --required-resource-accesses './manifest.json' --password $global:appSecret --end-date '2299-12-31T11:59:59+00:00'
$app = az ad app create --display-name $appName --required-resource-accesses './manifest.json'

$appId = $app | ConvertFrom-Json | Select-Object appid

$global:appId = $appId.appid

Write-Host "Waiting for app to finish creating..."

Expand All @@ -551,8 +563,16 @@ function CreateAzureADApp {

}

$app = GetAzureADApp $appName
$global:appId = $app.appId
Write-Host "Creating secret for Azure AD App - '$appName'..." -ForegroundColor Yellow

# Create a secret - this will autogenerate a password
$secret = az ad app credential reset --id $global:appId

$secretValue = $secret | ConvertFrom-Json | Select-Object password

$global:appSecret = $secretValue.password

Write-Host "Created secret for app" -ForegroundColor Green

Write-Host "Granting admin content for Microsoft Graph..." -ForegroundColor Yellow

Expand Down Expand Up @@ -782,13 +802,6 @@ Write-Host "Installed modules" -ForegroundColor Green

Write-Ascii -InputObject "Request-a-Team" -ForegroundColor Magenta

# Generate base64 secret for the app
$guid = New-Guid

$global:appSecret = ([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($guid))))

$global:encodedAppSecret = [System.Web.HttpUtility]::UrlEncode($global:appSecret)

# Initialise connections - Azure Az/CLI
Write-Host "Launching Azure sign-in..." -ForegroundColor Yellow
$azConnect = Connect-AzAccount -Subscription $SubscriptionId -Tenant $TenantId
Expand Down

0 comments on commit 77aca75

Please sign in to comment.