Skip to content

Commit 859ed68

Browse files
authored
Updated Sync (#5)
Updated script to remove the user requirement
1 parent 738618e commit 859ed68

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

Sync.ps1

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,7 @@ function New-GraphAccessToken() {
119119
[string]$ApplicationId,
120120

121121
[Parameter(Mandatory = $true)]
122-
[securestring]$ClientSecret,
123-
124-
[Parameter(Mandatory = $true)]
125-
[string]$Username,
126-
127-
[Parameter(Mandatory = $true)]
128-
[securestring]$Password
122+
[securestring]$ClientSecret
129123
)
130124

131125
begin {
@@ -139,12 +133,9 @@ function New-GraphAccessToken() {
139133
}
140134
Body = @{
141135
"resource" = "https://graph.microsoft.com"
142-
"grant_type" = "password"
136+
"grant_type" = "client_credentials"
143137
"client_id" = "$applicationId"
144138
"client_secret" = "$(ConvertFrom-SecureString -SecureString $clientSecret -AsPlainText)"
145-
"username" = "$username"
146-
"password" = "$(ConvertFrom-SecureString -SecureString $password -AsPlainText)"
147-
"scope" = "openid"
148139
}
149140
}
150141
}
@@ -238,18 +229,12 @@ function Initialization {
238229
$clientSecret = Read-Host -Prompt "Client Secret" -AsSecureString
239230
if ([string]::IsNullOrEmpty($clientSecret)) { Write-Error -Message "Client Secret cannot be blank." -ErrorAction Stop }
240231

241-
$username = Read-Host -Prompt "Username"
242-
if ([string]::IsNullOrEmpty($username)) { Write-Error -Message "Username cannot be blank." -ErrorAction Stop }
243-
244-
$password = Read-Host -Prompt "Password" -AsSecureString
245-
if ([string]::IsNullOrEmpty($password)) { Write-Error -Message "Password cannot be blank." -ErrorAction Stop }
246-
247232
Clear-Host
248233
Write-Host "AWS Single Sign-On Integration - Sync Starting" -ForegroundColor Yellow
249234
}
250235

251236
process {
252-
$accessToken = New-GraphAccessToken -TenantId $tenantId -ApplicationId $applicationId -ClientSecret $clientSecret -Username $username -Password $password
237+
$accessToken = New-GraphAccessToken -TenantId $tenantId -ApplicationId $applicationId -ClientSecret $clientSecret
253238
$servicePrincipalId = Get-GraphServicePrincipal -AccessToken $accessToken -DisplayName $displayName
254239
$jobId = Get-GraphSynchronizationJobId -AccessToken $accessToken -ServicePrincipalId $servicePrincipalId
255240
Start-GraphSynchronizationJob -AccessToken $accessToken -ServicePrincipalId $servicePrincipalId -JobId $jobId

0 commit comments

Comments
 (0)