You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Modules/CIPPCore/Public/GraphHelper/New-DeviceLogin.ps1
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -11,16 +11,24 @@ function New-DeviceLogin {
11
11
[string]$device_code,
12
12
[string]$TenantId
13
13
)
14
-
$encodedscope= [uri]::EscapeDataString($scope)
15
14
if ($FirstLogon) {
15
+
$Body=@{
16
+
client_id=$Clientid
17
+
scope="$scope offline_access profile openid"
18
+
}
16
19
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'
19
21
} 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'
21
23
}
22
24
} 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'
0 commit comments