Skip to content

Commit 353d9db

Browse files
authored
Merge branch 'dev' into profileformat
2 parents f591a05 + c0d8374 commit 353d9db

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

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)