Skip to content

Commit 77aca75

Browse files
alexc-MSFTAlex Clark
and
Alex Clark
authored
Updates to CLI calls to create/update azure ad app (#363)
* Updates to CLI calls to create/update azure ad app * Removed guid generation Co-authored-by: Alex Clark <[email protected]>
1 parent 23a91d1 commit 77aca75

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

Deployment/Scripts/deploy.ps1

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,22 @@ function InstallModules ($modules) {
255255
if ($spModule) {
256256
throw('Please remove the older "SharePointPnPPowerShellOnline" module before the deployment can install the new cross-platform module "PnP.PowerShell"')
257257
}
258+
else {
259+
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false -MaximumVersion 1.9.0
260+
}
258261
}
259-
260-
try {
261-
Write-Host('Installing required PowerShell Module {0}' -f $module) -ForegroundColor Yellow
262-
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false
262+
else {
263+
try {
264+
Write-Host('Installing required PowerShell Module {0}' -f $module) -ForegroundColor Yellow
265+
Install-Module -Name $module -Scope CurrentUser -AllowClobber -Confirm:$false
266+
}
267+
catch {
268+
throw('Failed to install PowerShell module {0}: {1}' -f $module, $_.Exception.Message)
269+
}
263270
}
264-
catch {
265-
throw('Failed to install PowerShell module {0}: {1}' -f $module, $_.Exception.Message)
266-
}
271+
267272
}
273+
268274
}
269275

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

530-
az ad app update --id $app.appId --required-resource-accesses './manifest.json' --password $global:appSecret
536+
az ad app update --id $app.appId --required-resource-accesses './manifest.json'
537+
538+
$global:appId = $app.appId
531539

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

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

543551
# Create azure ad app registration using CLI
544-
az ad app create --display-name $appName --required-resource-accesses './manifest.json' --password $global:appSecret --end-date '2299-12-31T11:59:59+00:00'
552+
$app = az ad app create --display-name $appName --required-resource-accesses './manifest.json'
553+
554+
$appId = $app | ConvertFrom-Json | Select-Object appid
555+
556+
$global:appId = $appId.appid
545557

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

@@ -551,8 +563,16 @@ function CreateAzureADApp {
551563

552564
}
553565

554-
$app = GetAzureADApp $appName
555-
$global:appId = $app.appId
566+
Write-Host "Creating secret for Azure AD App - '$appName'..." -ForegroundColor Yellow
567+
568+
# Create a secret - this will autogenerate a password
569+
$secret = az ad app credential reset --id $global:appId
570+
571+
$secretValue = $secret | ConvertFrom-Json | Select-Object password
572+
573+
$global:appSecret = $secretValue.password
574+
575+
Write-Host "Created secret for app" -ForegroundColor Green
556576

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

@@ -782,13 +802,6 @@ Write-Host "Installed modules" -ForegroundColor Green
782802

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

785-
# Generate base64 secret for the app
786-
$guid = New-Guid
787-
788-
$global:appSecret = ([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($guid))))
789-
790-
$global:encodedAppSecret = [System.Web.HttpUtility]::UrlEncode($global:appSecret)
791-
792805
# Initialise connections - Azure Az/CLI
793806
Write-Host "Launching Azure sign-in..." -ForegroundColor Yellow
794807
$azConnect = Connect-AzAccount -Subscription $SubscriptionId -Tenant $TenantId

0 commit comments

Comments
 (0)