Skip to content

Commit 37fd98b

Browse files
committed
Removed browser based popup auth
1 parent 15a975b commit 37fd98b

File tree

10 files changed

+142
-154
lines changed

10 files changed

+142
-154
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "PowerShell cmdlets: pwsh",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "Build with nugets",
12+
"program": "pwsh",
13+
"args": [
14+
"-NoExit",
15+
"-NoProfile",
16+
"-Command",
17+
"Import-Module ${userHome}/.local/share/powershell/Modules/PnP.PowerShell.psd1",
18+
],
19+
"cwd": "${workspaceFolder}",
20+
"stopAtEntry": false,
21+
"console": "externalTerminal"
22+
},
723
{
824
"name": ".NET Core Launch with Nuget Build(console)",
925
"type": "coreclr",
@@ -13,6 +29,7 @@
1329
"cwd": "${workspaceFolder}",
1430
"stopAtEntry": false,
1531
"console": "externalTerminal",
32+
"program": "pwsh",
1633
"osx": {
1734
"program": "pwsh",
1835
},

src/Commands/AzureAD/RegisterAzureADApp.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private string GetAuthToken(CmdletMessageWriter messageWriter)
437437
{
438438
Task.Factory.StartNew(() =>
439439
{
440-
token = AzureAuthHelper.AuthenticateDeviceLogin(cancellationTokenSource, messageWriter, NoPopup, AzureEnvironment, MicrosoftGraphEndPoint, launchBrowser: LaunchBrowser);
440+
token = AzureAuthHelper.AuthenticateDeviceLogin(cancellationTokenSource, messageWriter, AzureEnvironment, MicrosoftGraphEndPoint, launchBrowser: LaunchBrowser);
441441
if (token == null)
442442
{
443443
messageWriter.WriteWarning("Operation cancelled or no token retrieved.");
@@ -450,7 +450,7 @@ private string GetAuthToken(CmdletMessageWriter messageWriter)
450450
{
451451
Task.Factory.StartNew(() =>
452452
{
453-
token = AzureAuthHelper.AuthenticateInteractive(cancellationTokenSource, messageWriter, NoPopup, AzureEnvironment, Tenant, MicrosoftGraphEndPoint);
453+
token = AzureAuthHelper.AuthenticateInteractive(cancellationTokenSource, messageWriter, AzureEnvironment, Tenant, MicrosoftGraphEndPoint);
454454
if (token == null)
455455
{
456456
messageWriter.WriteWarning("Operation cancelled or no token retrieved.");
@@ -692,7 +692,7 @@ private void StartConsentFlow(string loginEndPoint, AzureADApp azureApp, string
692692
{
693693
using (var authManager = AuthenticationManager.CreateWithInteractiveLogin(azureApp.AppId, (url, port) =>
694694
{
695-
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, !LaunchBrowser, cancellationTokenSource);
695+
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, cancellationTokenSource);
696696
}, Tenant, "You successfully provided consent", "You failed to provide consent.", AzureEnvironment))
697697
{
698698
authManager.ClearTokenCache();
@@ -705,18 +705,18 @@ private void StartConsentFlow(string loginEndPoint, AzureADApp azureApp, string
705705
{
706706
ClipboardService.SetText(deviceCodeResult.UserCode);
707707
messageWriter.WriteWarning($"\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");
708-
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), false, cancellationTokenSource);
708+
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource);
709709
return Task.FromResult(0);
710710
}, AzureEnvironment))
711711
{
712712
authManager.ClearTokenCache();
713713
authManager.GetAccessToken(resource, Microsoft.Identity.Client.Prompt.Consent);
714714
}
715715
}
716-
else
717-
{
718-
BrowserHelper.GetWebBrowserPopup(consentUrl, "Please provide consent", new[] { ("https://pnp.github.io/powershell/consent.html", BrowserHelper.UrlMatchType.StartsWith) }, cancellationTokenSource: cancellationTokenSource, cancelOnClose: false);
719-
}
716+
// else
717+
// {
718+
// BrowserHelper.GetWebBrowserPopup(consentUrl, "Please provide consent", new[] { ("https://pnp.github.io/powershell/consent.html", BrowserHelper.UrlMatchType.StartsWith) }, cancellationTokenSource: cancellationTokenSource, cancelOnClose: false);
719+
// }
720720
// Write results
721721
WriteObject(record);
722722
}

src/Commands/AzureAD/RegisterEntraIDAppForInteractiveLogin.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private string GetAuthToken(CmdletMessageWriter messageWriter)
358358
{
359359
Task.Factory.StartNew(() =>
360360
{
361-
token = AzureAuthHelper.AuthenticateDeviceLogin(cancellationTokenSource, messageWriter, NoPopup, AzureEnvironment, MicrosoftGraphEndPoint, launchBrowser: LaunchBrowser);
361+
token = AzureAuthHelper.AuthenticateDeviceLogin(cancellationTokenSource, messageWriter, AzureEnvironment, MicrosoftGraphEndPoint, launchBrowser: LaunchBrowser);
362362
if (token == null)
363363
{
364364
messageWriter.WriteWarning("Operation cancelled or no token retrieved.");
@@ -371,7 +371,7 @@ private string GetAuthToken(CmdletMessageWriter messageWriter)
371371
{
372372
Task.Factory.StartNew(() =>
373373
{
374-
token = AzureAuthHelper.AuthenticateInteractive(cancellationTokenSource, messageWriter, NoPopup, AzureEnvironment, Tenant, MicrosoftGraphEndPoint);
374+
token = AzureAuthHelper.AuthenticateInteractive(cancellationTokenSource, messageWriter, AzureEnvironment, Tenant, MicrosoftGraphEndPoint);
375375
if (token == null)
376376
{
377377
messageWriter.WriteWarning("Operation cancelled or no token retrieved.");
@@ -509,7 +509,7 @@ private void StartConsentFlow(string loginEndPoint, AzureADApp azureApp, string
509509
{
510510
using (var authManager = AuthenticationManager.CreateWithInteractiveLogin(azureApp.AppId, (url, port) =>
511511
{
512-
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, !LaunchBrowser, cancellationTokenSource);
512+
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, cancellationTokenSource);
513513
}, Tenant, "You successfully provided consent", "You failed to provide consent.", AzureEnvironment))
514514
{
515515
authManager.ClearTokenCache();
@@ -522,18 +522,18 @@ private void StartConsentFlow(string loginEndPoint, AzureADApp azureApp, string
522522
{
523523
ClipboardService.SetText(deviceCodeResult.UserCode);
524524
messageWriter.WriteWarning($"\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");
525-
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), false, cancellationTokenSource);
525+
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource);
526526
return Task.FromResult(0);
527527
}, AzureEnvironment))
528528
{
529529
authManager.ClearTokenCache();
530530
authManager.GetAccessToken(resource, Microsoft.Identity.Client.Prompt.Consent);
531531
}
532532
}
533-
else
534-
{
535-
BrowserHelper.GetWebBrowserPopup(consentUrl, "Please provide consent", new[] { ("https://pnp.github.io/powershell/consent.html", BrowserHelper.UrlMatchType.StartsWith) }, cancellationTokenSource: cancellationTokenSource, cancelOnClose: false);
536-
}
533+
// else
534+
// {
535+
// BrowserHelper.GetWebBrowserPopup(consentUrl, "Please provide consent", new[] { ("https://pnp.github.io/powershell/consent.html", BrowserHelper.UrlMatchType.StartsWith) }, cancellationTokenSource: cancellationTokenSource, cancelOnClose: false);
536+
// }
537537
// Write results
538538

539539
WriteObject($"App created. You can now connect to your tenant using Connect-PnPOnline -Url <yourtenanturl> -Interactive -ClientId {azureApp.AppId}");

src/Commands/Base/ConnectOnline.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public class ConnectOnline : BasePSCmdlet
149149
public SwitchParameter DeviceLogin;
150150

151151
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_DEVICELOGIN)]
152-
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_INTERACTIVE)]
153152
public SwitchParameter LaunchBrowser;
154153

155154
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_CREDENTIALS)]

src/Commands/Base/PnPConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ internal static PnPConnection CreateWithDeviceLogin(string clientId, string url,
269269
{
270270
ClipboardService.SetText(deviceCodeResult.UserCode);
271271
messageWriter.WriteWarning($"\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");
272-
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), false, cancellationTokenSource);
272+
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource);
273273
}
274274
else
275275
{
@@ -587,7 +587,7 @@ internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientI
587587
{
588588
authManager = PnP.Framework.AuthenticationManager.CreateWithInteractiveWebBrowserLogin(clientId, (url, port) =>
589589
{
590-
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, !launchBrowser, cancellationTokenSource);
590+
BrowserHelper.OpenBrowserForInteractiveLogin(url, port, cancellationTokenSource);
591591
},
592592
tenant,
593593
htmlMessageSuccess,

src/Commands/PnP.PowerShell.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="WindowsSdk.targets" Condition="'$(OS)' == 'Windows_NT'" />
3-
<Import Project="Sdk.targets" Condition="'$(OS)' != 'Windows_NT'" />
4-
2+
53
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
65
<LangVersion>12</LangVersion>
76
</PropertyGroup>
87

@@ -114,8 +113,8 @@
114113
</Reference>
115114
</ItemGroup>
116115

117-
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
118-
<PackageReference Include="System.Management.Automation" Version="7.4.4" />
116+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
117+
<PackageReference Include="System.Management.Automation" Version="7.4.6" />
119118
<PackageReference Include="TextCopy" Version="6.2.1" />
120119
</ItemGroup>
121120

src/Commands/Sdk.targets

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)