Skip to content

Commit fb90459

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell-common into fix_resourceId
2 parents 8dd81f1 + c0d8374 commit fb90459

File tree

13 files changed

+78
-27
lines changed

13 files changed

+78
-27
lines changed

src/Authentication.Abstractions/Authentication.Abstractions.Netcore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</PropertyGroup>
3939

4040
<ItemGroup>
41-
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.4" />
41+
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.5" />
4242
</ItemGroup>
4343

4444
<ItemGroup>

src/Authentication.Abstractions/AzureEnvironmentConstants.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public static class AzureEnvironmentConstants
130130
/// <summary>
131131
/// The domain name suffix for Azure DataLake services
132132
/// </summary>
133-
public const string AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = "azuredatalakeanalytics.net";
134-
public const string AzureDataLakeStoreFileSystemEndpointSuffix = "azuredatalakestore.net";
133+
public const string AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = "azuredatalakeanalytics.net/";
134+
public const string AzureDataLakeStoreFileSystemEndpointSuffix = "azuredatalakestore.net/";
135135

136136
/// <summary>
137137
/// The token audience for authorizing DataLake requests

src/Authentication.Abstractions/packages.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
99
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
1010
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
11-
<package id="Microsoft.Rest.ClientRuntime" version="2.3.14" targetFramework="net452" />
12-
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.16" targetFramework="net452" />
11+
<package id="Microsoft.Rest.ClientRuntime" version="2.3.17" targetFramework="net452" />
12+
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.18" targetFramework="net452" />
1313
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.1" targetFramework="net452" />
1414
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
1515
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net40" />
@@ -19,8 +19,8 @@
1919
<package id="Microsoft.Azure.Management.Resources" version="2.20.1-preview" targetFramework="net40" />
2020
<package id="Microsoft.Azure.Management.ResourceManager" version="1.9.0-preview" targetFramework="net452" />
2121
<package id="Microsoft.Azure.Test.Framework" version="3.0.0" targetFramework="net452" />
22-
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.13.0" targetFramework="net452" />
23-
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.7.4" targetFramework="net452" />
22+
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.13.1" targetFramework="net452" />
23+
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.7.5" targetFramework="net452" />
2424
<package id="Microsoft.WindowsAzure.Management.Compute" version="14.0.0" targetFramework="net45" />
2525
<package id="Microsoft.WindowsAzure.Management.Storage" version="6.0.1" targetFramework="net45" />
2626
<package id="Moq" version="4.2.1510.2205" targetFramework="net40" />

src/Authentication.ResourceManager/AzureRmProfile.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ public bool TryGetContextName(IAzureContext context, out string name)
401401
name = string.Format("{0} ({1}) - {2}", context.Subscription.Name, context.Subscription.Id, context.Account.Id);
402402
result = true;
403403
}
404+
else if (context.Tenant != null && context.Account != null)
405+
{
406+
name = string.Format("{0} - {1}", context.Tenant.Id, context.Account.Id);
407+
result = true;
408+
}
404409
else
405410
{
406411
name = "Default";

src/Authentication.Test/Cmdlets/ConnectAccount.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public class ConnectAccount : AzureRMCmdlet
5858
[Parameter(Mandatory = false)]
5959
public string Password { get; set; }
6060

61+
[Parameter(Mandatory = false)]
62+
public string ApplicationId { get; set; }
63+
64+
[Parameter(Mandatory = false)]
65+
public string CertificateThumbprint { get; set; }
66+
6167
protected override void BeginProcessing()
6268
{
6369
_profile = new AzureRmAutosaveProfile(
@@ -89,6 +95,16 @@ public override void ExecuteCmdlet()
8995
password = _credential.Password;
9096
}
9197

98+
if (!string.IsNullOrEmpty(ApplicationId))
99+
{
100+
Account.Id = ApplicationId;
101+
}
102+
103+
if (!string.IsNullOrEmpty(CertificateThumbprint))
104+
{
105+
Account.SetThumbprint(CertificateThumbprint);
106+
}
107+
92108
if (!string.IsNullOrEmpty(TenantId))
93109
{
94110
Account.SetProperty(AzureAccount.Property.Tenants, new[] { TenantId });

src/Authentication.Test/LoginTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class LoginTests
4747
private string _subscriptionName = null;
4848
private string _userName = null;
4949
private string _password = null;
50+
private string _applicationId = null;
51+
private string _certificateThumbprint = null;
5052

5153
public LoginTests()
5254
{
@@ -65,6 +67,8 @@ public LoginTests()
6567
_cmdlet.SubscriptionName = _subscriptionName;
6668
_cmdlet.UserName = _userName;
6769
_cmdlet.Password = _password;
70+
_cmdlet.ApplicationId = _applicationId;
71+
_cmdlet.CertificateThumbprint = _certificateThumbprint;
6872
_cmdlet.CommandRuntime = new MockCommandRuntime();
6973
}
7074

@@ -96,6 +100,18 @@ public void LoginWithServicePrincipal()
96100
Login();
97101
}
98102

103+
[Fact]
104+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
105+
public void LoginWithCertificate()
106+
{
107+
// REQUIRED:
108+
// _tenantId --> Id of the tenant that the service principal is registered to
109+
// _applicationId --> Application id of the service principal
110+
// _certificateThumbprint --> Thumbprint of the certificate used to authenticate the service principal
111+
_account = new AzureAccount() { Type = AzureAccount.AccountType.ServicePrincipal };
112+
Login();
113+
}
114+
99115
private void EnableAutosave(IAzureSession session, bool writeAutoSaveFile, out ContextAutosaveSettings result)
100116
{
101117
var store = session.DataStore;

src/Authentication/Authentication/AdalTokenProvider.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ public IAccessToken GetAccessToken(
126126
throw new ArgumentException(Resources.UnsupportedCredentialType, "credentialType");
127127
}
128128
}
129+
130+
public IAccessToken GetAccessTokenWithCertificate(
131+
AdalConfiguration config,
132+
string clientId,
133+
string certificate,
134+
string credentialType)
135+
{
136+
switch (credentialType)
137+
{
138+
case AzureAccount.AccountType.ServicePrincipal:
139+
return servicePrincipalTokenProvider.GetAccessTokenWithCertificate(config, clientId, certificate, credentialType);
140+
default:
141+
throw new ArgumentException(string.Format(Resources.UnsupportedCredentialType, credentialType), "credentialType");
142+
}
143+
}
129144
#endif
130145

131146
}

src/Authentication/Authentication/ITokenProvider.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ IAccessToken GetAccessToken(
4242
string userId,
4343
SecureString password,
4444
string credentialType);
45-
46-
#if !NETSTANDARD
45+
4746
/// <summary>
4847
/// Get a new authentication token for the given environment
4948
/// </summary>
@@ -57,6 +56,5 @@ IAccessToken GetAccessTokenWithCertificate(
5756
string principalId,
5857
string certificateThumbprint,
5958
string credentialType);
60-
#endif
6159
}
6260
}

src/Authentication/Authentication/UserTokenProvider.Netcore.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ private void Renew(AdalAccessToken token)
106106

107107
private AuthenticationContext CreateContext(AdalConfiguration config)
108108
{
109-
return new AuthenticationContext(config.AdEndpoint + config.AdDomain,
109+
return new AuthenticationContext(config.AdEndpoint + config.AdDomain,
110110
config.ValidateAuthority, config.TokenCache);
111111
}
112112

113113
// We have to run this in a separate thread to guarantee that it's STA. This method
114114
// handles the threading details.
115-
private AuthenticationResult AcquireToken(AdalConfiguration config, Action<string> promptAction,
115+
private AuthenticationResult AcquireToken(AdalConfiguration config, Action<string> promptAction,
116116
string userId, SecureString password, bool renew = false)
117117
{
118118
AuthenticationResult result = null;
@@ -237,6 +237,11 @@ private string GetExceptionMessage(Exception ex)
237237
return message;
238238
}
239239

240+
public IAccessToken GetAccessTokenWithCertificate(AdalConfiguration config, string principalId, string certificateThumbprint, string credentialType)
241+
{
242+
throw new NotImplementedException();
243+
}
244+
240245
/// <summary>
241246
/// Implementation of <see cref="IRenewableToken"/> using data from ADAL
242247
/// </summary>

src/Authentication/Factories/AuthenticationFactory.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ public IAccessToken Authenticate(
136136
else if (account.IsPropertySet(AzureAccount.Property.CertificateThumbprint))
137137
{
138138
var thumbprint = account.GetProperty(AzureAccount.Property.CertificateThumbprint);
139-
#if !NETSTANDARD
140139
token = TokenProvider.GetAccessTokenWithCertificate(configuration, account.Id, thumbprint, account.Type);
141-
#else
142-
throw new NotSupportedException("Certificate based authentication is not supported in netcore version.");
143-
#endif
144140
}
145141
else
146142
{

0 commit comments

Comments
 (0)