Skip to content

Commit 0c84c55

Browse files
authored
Merge pull request #3255 from cormacpayne/improve-error-message
Improve error message when using MSA with -Credential parameter
2 parents b833d86 + 6f0bfa1 commit 0c84c55

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Common/Commands.Common.Authentication/Authentication/UserTokenProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ private AuthenticationResult SafeAquireToken(
189189

190190
ex = new AadAuthenticationFailedWithoutPopupException(message, adalEx);
191191
}
192-
else if (adalEx.ErrorCode == AdalError.MissingFederationMetadataUrl)
192+
else if (adalEx.ErrorCode == AdalError.MissingFederationMetadataUrl ||
193+
adalEx.ErrorCode == AdalError.FederatedServiceReturnedError)
193194
{
194195
ex = new AadAuthenticationFailedException(Resources.CredentialOrganizationIdMessage, adalEx);
195196
}

src/ResourceManager/Profile/Commands.Profile.Test/LoginCmdletTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using System.Collections.Generic;
2727
using System.Net.Http.Headers;
2828
using System.Diagnostics;
29+
using System;
30+
using System.Security;
2931

3032
namespace Microsoft.Azure.Commands.Profile.Test
3133
{
@@ -292,6 +294,43 @@ public void LoginWithEnvironementName()
292294
Assert.Equal("AzureUSGovernment", AzureRmProfileProvider.Instance.Profile.Context.Environment.Name);
293295
}
294296

297+
[Fact]
298+
[Trait(Category.RunType, Category.LiveOnly)]
299+
public void LoginWithCredentialParameterAndMSA()
300+
{
301+
var cmdlt = new AddAzureRMAccountCommand();
302+
// Setup
303+
cmdlt.CommandRuntime = commandRuntimeMock;
304+
305+
// Example of environment variable: TEST_AZURE_CREDENTIALS=<subscription-id-value>;<[email protected]>;<email-password>"
306+
string credsEnvironmentVariable = Environment.GetEnvironmentVariable("TEST_AZURE_CREDENTIALS");
307+
string[] creds = credsEnvironmentVariable.Split(';');
308+
309+
string userName = creds[1];
310+
string password = creds[2];
311+
312+
var securePassword = new SecureString();
313+
Array.ForEach(password.ToCharArray(), securePassword.AppendChar);
314+
315+
cmdlt.Credential = new PSCredential(userName, securePassword);
316+
317+
// Act
318+
try
319+
{
320+
cmdlt.InvokeBeginProcessing();
321+
cmdlt.ExecuteCmdlet();
322+
cmdlt.InvokeEndProcessing();
323+
}
324+
catch (AadAuthenticationFailedException ex)
325+
{
326+
Assert.NotNull(ex);
327+
Assert.Equal("-Credential parameter can only be used with Organization ID credentials. " +
328+
"For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409 " +
329+
"for more information about the difference between an organizational account and a Microsoft account.",
330+
ex.Message);
331+
}
332+
}
333+
295334
[Fact]
296335
[Trait(Category.AcceptanceType, Category.CheckIn)]
297336
public void ThrowOnUnknownEnvironment()

0 commit comments

Comments
 (0)