Skip to content

Commit 619dc26

Browse files
author
Maddie Clayton
authored
Merge branch 'dev' into types
2 parents 24eaa2a + c0d8374 commit 619dc26

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
@@ -50,6 +50,8 @@ public class LoginTests
5050
private string _subscriptionName = null;
5151
private string _userName = null;
5252
private string _password = null;
53+
private string _applicationId = null;
54+
private string _certificateThumbprint = null;
5355

5456
public LoginTests()
5557
{
@@ -68,6 +70,8 @@ public LoginTests()
6870
_cmdlet.SubscriptionName = _subscriptionName;
6971
_cmdlet.UserName = _userName;
7072
_cmdlet.Password = _password;
73+
_cmdlet.ApplicationId = _applicationId;
74+
_cmdlet.CertificateThumbprint = _certificateThumbprint;
7175
_cmdlet.CommandRuntime = new MockCommandRuntime();
7276
}
7377

@@ -99,6 +103,18 @@ public void LoginWithServicePrincipal()
99103
Login();
100104
}
101105

106+
[Fact]
107+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
108+
public void LoginWithCertificate()
109+
{
110+
// REQUIRED:
111+
// _tenantId --> Id of the tenant that the service principal is registered to
112+
// _applicationId --> Application id of the service principal
113+
// _certificateThumbprint --> Thumbprint of the certificate used to authenticate the service principal
114+
_account = new AzureAccount() { Type = AzureAccount.AccountType.ServicePrincipal };
115+
Login();
116+
}
117+
102118
private void EnableAutosave(IAzureSession session, bool writeAutoSaveFile, out ContextAutosaveSettings result)
103119
{
104120
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)