Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Accounts/Accounts.Test/AzureRMProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ public void LoadingProfileWorks()


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void CanRenewTokenLogin()
{
var tenants = new List<string> { DefaultTenant.ToString() };
Expand Down
2 changes: 1 addition & 1 deletion src/Accounts/Accounts.Test/LoginCmdletTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void ThrowOnUnknownEnvironment()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void LoginUsingSkipValidation()
{
var cmdlt = new ConnectAzureRmAccountCommand();
Expand Down
68 changes: 47 additions & 21 deletions src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Management.Automation;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Azure.Identity;

using Microsoft.Azure.Commands.Common.Authentication;
Expand All @@ -30,24 +20,33 @@
using Microsoft.Azure.Commands.Common.Authentication.Factories;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager.Common;
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer;
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.Profile.Models.Core;
using Microsoft.Azure.Commands.Profile.Properties;
using Microsoft.Azure.Commands.Profile.Utilities;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Shared.Config;
using Microsoft.Azure.PowerShell.Authenticators;
using Microsoft.Azure.PowerShell.Authenticators.Factories;
using Microsoft.Azure.PowerShell.Common.Config;
using Microsoft.Azure.PowerShell.Common.Share.Survey;
using Microsoft.Identity.Client;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
using Microsoft.WindowsAzure.Commands.Common.Utilities;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.PowerShell.Common.Share.Survey;
using Microsoft.Azure.Commands.Profile.Utilities;
using System.Management.Automation.Runspaces;
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer;

using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Management.Automation;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.Profile
{
Expand Down Expand Up @@ -328,6 +327,7 @@ public override void ExecuteCmdlet()
Guid subscriptionIdGuid;
string subscriptionName = null;
string subscriptionId = null;
bool isInteractiveAuthentication = IsInteractiveAuthentication();
if (MyInvocation.BoundParameters.ContainsKey(nameof(Subscription)))
{
if (Guid.TryParse(Subscription, out subscriptionIdGuid))
Expand Down Expand Up @@ -506,7 +506,7 @@ public override void ExecuteCmdlet()
commonUtilities = new CommonUtilities();
AzureSession.Instance.RegisterComponent(nameof(CommonUtilities), () => commonUtilities);
}
if (!commonUtilities.IsDesktopSession() && IsUsingInteractiveAuthentication())
if (!commonUtilities.IsDesktopSession() && IsBrowserPopUpInteractiveAuthentication())
{
WriteWarning(Resources.InteractiveAuthNotSupported);
return;
Expand All @@ -523,8 +523,10 @@ public override void ExecuteCmdlet()
shouldPopulateContextList = false;
}

profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
profileClient.InformationLog = (message) => _tasks.Enqueue(new Task(() => this.WriteInformation(message, false)));
profileClient.DebugLog = (message) => _tasks.Enqueue(new Task(() => this.WriteDebugWithTimestamp(message)));

var task = new Task<AzureRmProfile>(() => profileClient.Login(
azureAccount,
_environment,
Expand All @@ -538,7 +540,9 @@ public override void ExecuteCmdlet()
name,
shouldPopulateContextList,
MaxContextPopulation,
resourceId));
resourceId,
Prompt,
isInteractiveAuthentication));
task.Start();
while (!task.IsCompleted)
{
Expand Down Expand Up @@ -569,7 +573,7 @@ public override void ExecuteCmdlet()
}
else
{
if (IsUsingInteractiveAuthentication())
if (IsBrowserPopUpInteractiveAuthentication())
{
//Display only if user is using Interactive auth
WriteWarning(Resources.SuggestToUseDeviceCodeAuth);
Expand All @@ -579,9 +583,17 @@ public override void ExecuteCmdlet()
}
}
});

WriteInformation($"[Announcements]{System.Environment.NewLine}Share your feedback regarding your experience with `Connect-AzAccount` at: https://aka.ms/azloginfeedback{System.Environment.NewLine}");
WriteInformation($"If you encounter any problem, please open an issue at: https://aka.ms/azpsissue{System.Environment.NewLine}");
}
}

private bool IsInteractiveAuthentication()
{
return ParameterSetName.Equals(UserParameterSet);
}

private void ValidateActionRequiredMessageCanBePresented()
{
if (UseDeviceAuthentication.IsPresent && IsWriteInformationIgnored())
Expand All @@ -608,9 +620,9 @@ private string PreProcessAuthScope()
return mappedScope;
}

private bool IsUsingInteractiveAuthentication()
private bool IsBrowserPopUpInteractiveAuthentication()
{
return ParameterSetName == UserParameterSet && UseDeviceAuthentication == false;
return ParameterSetName.Equals(UserParameterSet) && UseDeviceAuthentication.IsPresent == false;
}

private bool IsUnableToOpenWebPageError(AuthenticationFailedException exception)
Expand Down Expand Up @@ -654,6 +666,20 @@ private void WriteWarningEvent(string message)
}
}

private void WriteInformationEvent(string message)
{
EventHandler<StreamEventArgs> writeInformationEvent;
if (AzureSession.Instance.TryGetComponent(WriteInformationKey, out writeInformationEvent))
{
writeInformationEvent(this, new StreamEventArgs() { Message = message });
}
}
private string Prompt(string message)
{
_tasks.Enqueue(new Task(() => this.WriteInformation(message, true)));
return this.Host.UI.ReadLine();
}

private static bool CheckForExistingContext(AzureRmProfile profile, string name)
{
return name != null && profile?.Contexts != null && profile.Contexts.ContainsKey(name);
Expand Down
24 changes: 4 additions & 20 deletions src/Accounts/Accounts/Accounts.generated.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,23 @@
<TableHeaders>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Account</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>SubscriptionName</Label>
<Label>Subscription name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>TenantId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Environment</Label>
<Label>Tenant</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<Alignment>Left</Alignment>
<ScriptBlock>$_.Context.Account.ToString()</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<ScriptBlock>$_.Context.Subscription.Name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<ScriptBlock>$_.Context.Tenant.ToString()</ScriptBlock>
<ScriptBlock>if($null -ne $_.Context.Subscription.Name){$_.Context.Subscription.Name}else{$_.Context.Subscription.Id}</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<ScriptBlock>$_.Context.Environment.ToString()</ScriptBlock>
<ScriptBlock>if($null -ne $_.Context.Tenant.DefaultDomain){$_.Context.Tenant.DefaultDomain}else{$_.Context.Tenant.Id}</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
Expand Down
Loading