Skip to content

Commit 3523a9f

Browse files
committed
tweaks
1 parent 784497f commit 3523a9f

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

Modules/CIPPCore/Public/GraphHelper/New-DeviceLogin.ps1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,24 @@ function New-DeviceLogin {
1111
[string]$device_code,
1212
[string]$TenantId
1313
)
14-
$encodedscope = [uri]::EscapeDataString($scope)
1514
if ($FirstLogon) {
15+
$Body = @{
16+
client_id = $Clientid
17+
scope = "$scope offline_access profile openid"
18+
}
1619
if ($TenantID) {
17-
$ReturnCode = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$($TenantID)/oauth2/v2.0/devicecode" -Method POST -Body "client_id=$($Clientid)&scope=$encodedscope+offline_access+profile+openid"
18-
20+
$ReturnCode = Invoke-CIPPRestMethod -Uri "https://login.microsoftonline.com/$($TenantID)/oauth2/v2.0/devicecode" -Method POST -Body $Body -ContentType 'application/x-www-form-urlencoded'
1921
} else {
20-
$ReturnCode = Invoke-RestMethod -Uri 'https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode' -Method POST -Body "client_id=$($Clientid)&scope=$encodedscope+offline_access+profile+openid"
22+
$ReturnCode = Invoke-CIPPRestMethod -Uri 'https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode' -Method POST -Body $Body -ContentType 'application/x-www-form-urlencoded'
2123
}
2224
} else {
23-
$Checking = Invoke-RestMethod -SkipHttpErrorCheck -Uri 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token' -Method POST -Body "client_id=$($Clientid)&scope=$encodedscope+offline_access+profile+openid&grant_type=device_code&device_code=$($device_code)"
25+
$Body = @{
26+
client_id = $Clientid
27+
scope = "$scope offline_access profile openid"
28+
grant_type = 'device_code'
29+
device_code = $device_code
30+
}
31+
$Checking = Invoke-CIPPRestMethod -SkipHttpErrorCheck -Uri 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token' -Method POST -Body $Body -ContentType 'application/x-www-form-urlencoded'
2432
if ($checking.refresh_token) {
2533
$ReturnCode = $Checking
2634
} else {

Modules/CIPPCore/Public/Invoke-CIPPRestMethod.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ function Invoke-CIPPRestMethod {
128128
$BodyString = ''
129129
} elseif ($Body -is [string]) {
130130
$BodyString = $Body
131-
# Match Invoke-RestMethod default: string POST body → form-encoded
132-
if ($null -eq $ContentType) { $ContentType = 'application/x-www-form-urlencoded' }
133131
} elseif (
134132
($Body -is [System.Collections.IDictionary]) -and
135133
($null -eq $ContentType -or $ContentType -like 'application/x-www-form-urlencoded*')

Shared/CIPPHttp/bin/CIPPHttp.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)