Skip to content

Commit 13872aa

Browse files
authored
Merge pull request #5058 from KoenZomers/FixDeviceLoginOnLinux
Fixing devicelogin not working on a desktopless Linux device
2 parents 9508fee + 030e451 commit 13872aa

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3434
- Fix `Add/Publish/Unpublish/Remove-PnPApp` cmdlets to properly handle the issue in no-script sites.
3535
- Fix `Get-PnPHubSiteChild` cmdlet to handle vanity domains. [#4965](https://github.com/pnp/powershell/pull/4965)
3636
- Fix `Connect-PnPOnline` not working correctly with `-DeviceLogin` in Azure Cloud Shell.
37+
- Fix `Connect-PnPOnline` not working correctly with `-DeviceLogin` in desktop-less environments, such as on a Raspberry Pi [#5058](https://github.com/pnp/powershell/pull/5058)
3738

3839
### Removed
3940

documentation/Connect-PnPOnline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-CreateDrive] [-DriveName
5656

5757
### DeviceLogin
5858
```powershell
59-
Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-PersistLogin] [-CreateDrive] [-DriveName <String>] [-DeviceLogin] -Tenant <String>
59+
Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-PersistLogin] [-CreateDrive] [-DriveName <String>] -DeviceLogin -Tenant <String>
6060
[-ClientId <String>] [-AzureEnvironment <AzureEnvironment>]
6161
[-ValidateConnection] [-MicrosoftGraphEndPoint <string>]
6262
[-AzureADLoginEndPoint <string>] [-Connection <PnPConnection>]

src/Commands/Base/PnPConnection.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,34 @@ internal static PnPConnection CreateWithDeviceLogin(string clientId, string url,
286286
}
287287
else
288288
{
289+
var copiedToClipboard = true;
289290
try
290291
{
291292
ClipboardService.SetText(deviceCodeResult.UserCode);
292293
}
293294
catch
294295
{
296+
copiedToClipboard = false;
297+
}
298+
299+
var browserOpened = true;
300+
try
301+
{
302+
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource);
303+
}
304+
catch
305+
{
306+
browserOpened = false;
307+
}
308+
309+
if (copiedToClipboard && browserOpened)
310+
{
311+
messageWriter.LogWarning($"\n\nCode {deviceCodeResult.UserCode} has been copied to your clipboard and a new tab in the browser has been opened. Please paste this code in there and proceed.\n\n");
312+
}
313+
else
314+
{
315+
messageWriter.LogWarning($"\n\nOpen a browser, navigate to {deviceCodeResult.VerificationUrl} and authenticate using code {deviceCodeResult.UserCode} to proceed.\n\n");
295316
}
296-
messageWriter.LogWarning($"\n\nCode {deviceCodeResult.UserCode} has been copied to your clipboard and a new tab in the browser has been opened. Please paste this code in there and proceed.\n\n");
297-
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource);
298317
}
299318

300319
return Task.FromResult(0);

0 commit comments

Comments
 (0)