-
Notifications
You must be signed in to change notification settings - Fork 375
Add AzureCloudShell detection and improve user prompts for device login #4997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Azure Cloud Shell detection and customizes device login prompts when running in Cloud Shell.
- Introduces
PSUtility.IsAzureCloudShell
to detect the Cloud Shell environment. - Updates device login workflows in
AzureAuthHelper
,PnPConnection
, and registration commands to show simplified instructions in Cloud Shell. - Wraps clipboard operations in try/catch and conditionally opens a browser only when not in Cloud Shell.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Commands/Utilities/PSUtility.cs | Add IsAzureCloudShell helper |
src/Commands/Utilities/AzureAuthHelper.cs | Conditionally adjust device login prompts for Cloud Shell |
src/Commands/Base/PnPConnection.cs | Apply Cloud Shell‐specific prompt adjustments |
src/Commands/AzureAD/RegisterEntraIDAppForInteractiveLogin.cs | Apply Cloud Shell prompts in Entra ID registration flow |
src/Commands/AzureAD/RegisterAzureADApp.cs | Apply Cloud Shell prompts in Azure AD registration flow |
Comments suppressed due to low confidence (3)
src/Commands/Utilities/PSUtility.cs:54
- Add an XML doc comment above this method to explain its purpose and the expected environment variable, improving discoverability and maintenance.
public static bool IsAzureCloudShell()
src/Commands/Utilities/PSUtility.cs:54
- Consider adding unit tests for
IsAzureCloudShell
to verify behavior when thePOWERSHELL_DISTRIBUTION_CHANNEL
variable is unset, empty, or set to "CloudShell" (in various cases).
public static bool IsAzureCloudShell()
src/Commands/Base/PnPConnection.cs:282
- Indentation and brace alignment around the new Cloud Shell conditional block is inconsistent. Align braces and indentation with surrounding code to improve readability.
{
return false; | ||
} | ||
|
||
return psDistChannel == "CloudShell"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a case‐insensitive comparison to avoid issues if the environment variable uses a different case. For example: return string.Equals(psDistChannel, "CloudShell", StringComparison.OrdinalIgnoreCase);
return psDistChannel == "CloudShell"; | |
return string.Equals(psDistChannel, "CloudShell", StringComparison.OrdinalIgnoreCase); |
Copilot uses AI. Check for mistakes.
if (PSUtility.IsAzureCloudShell()) | ||
{ | ||
messageWriter.LogWarning($"\n\nTo sign in, use a web browser to open the page {deviceCodeResult.VerificationUrl} and enter the code {deviceCodeResult.UserCode} to authenticate."); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
ClipboardService.SetText(deviceCodeResult.UserCode); | ||
} | ||
catch | ||
{ | ||
} | ||
messageWriter.LogWarning($"Please login.\n\nWe opened a browser and navigated to {deviceCodeResult.VerificationUrl}\n\nEnter code: {deviceCodeResult.UserCode} (we copied this code to your clipboard)\n\nNOTICE: close the browser tab after you authenticated successfully to continue the process."); | ||
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Device login prompt logic is duplicated in multiple places. Extract the Cloud Shell vs. local logic into a shared helper method to reduce duplication and keep messaging consistent.
if (PSUtility.IsAzureCloudShell()) | |
{ | |
messageWriter.LogWarning($"\n\nTo sign in, use a web browser to open the page {deviceCodeResult.VerificationUrl} and enter the code {deviceCodeResult.UserCode} to authenticate."); | |
} | |
else | |
{ | |
try | |
{ | |
ClipboardService.SetText(deviceCodeResult.UserCode); | |
} | |
catch | |
{ | |
} | |
messageWriter.LogWarning($"Please login.\n\nWe opened a browser and navigated to {deviceCodeResult.VerificationUrl}\n\nEnter code: {deviceCodeResult.UserCode} (we copied this code to your clipboard)\n\nNOTICE: close the browser tab after you authenticated successfully to continue the process."); | |
BrowserHelper.OpenBrowserForInteractiveLogin(deviceCodeResult.VerificationUrl, BrowserHelper.FindFreeLocalhostRedirectUri(), cancellationTokenSource); | |
} | |
HandleDeviceLoginPrompt(deviceCodeResult, messageWriter, cancellationTokenSource); |
Copilot uses AI. Check for mistakes.
Type
Related Issues?
Fixes #4983
What is in this Pull Request ?
Additional fixes for cloudshell issue