Skip to content

Commit c371971

Browse files
committed
dnxcore50 build for cmdlet base projects
1 parent ad227a8 commit c371971

File tree

79 files changed

+12324
-1551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+12324
-1551
lines changed

src/CLU/Microsoft.WindowsAzure.Commands.Common.sln renamed to src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.WindowsAzure.Commands.Common", "Microsoft.WindowsAzure.Commands.Common\Microsoft.WindowsAzure.Commands.Common.xproj", "{5F567ACA-595E-436D-83DB-A21E08F82DF6}"
77
EndProject
8+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commands.Common.Authentication", "Commands.Common.Authentication\Commands.Common.Authentication.xproj", "{4CE82310-D016-497D-93A0-0323A3E62064}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{5F567ACA-595E-436D-83DB-A21E08F82DF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{5F567ACA-595E-436D-83DB-A21E08F82DF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{5F567ACA-595E-436D-83DB-A21E08F82DF6}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{4CE82310-D016-497D-93A0-0323A3E62064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{4CE82310-D016-497D-93A0-0323A3E62064}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{4CE82310-D016-497D-93A0-0323A3E62064}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{4CE82310-D016-497D-93A0-0323A3E62064}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
17+
namespace Microsoft.Azure.Common.Authentication
18+
{
19+
/// <summary>
20+
/// Base class representing an exception that occurs when
21+
/// authenticating against Azure Active Directory
22+
/// </summary>
23+
//[Serializable]
24+
public abstract class AadAuthenticationException : Exception
25+
{
26+
protected AadAuthenticationException()
27+
{
28+
}
29+
30+
protected AadAuthenticationException(string message) : base(message)
31+
{
32+
}
33+
34+
protected AadAuthenticationException(string message, Exception innerException) : base(message, innerException)
35+
{
36+
}
37+
}
38+
39+
/// <summary>
40+
/// Exception that gets thrown when the user explicitly
41+
/// cancels an authentication operation.
42+
/// </summary>
43+
//[Serializable]
44+
public class AadAuthenticationCanceledException : AadAuthenticationException
45+
{
46+
public AadAuthenticationCanceledException(string message, Exception innerException) : base(message, innerException)
47+
{
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Exception that gets thrown when the ADAL library
53+
/// is unable to authenticate without a popup dialog.
54+
/// </summary>
55+
//[Serializable]
56+
public class AadAuthenticationFailedWithoutPopupException : AadAuthenticationException
57+
{
58+
public AadAuthenticationFailedWithoutPopupException(string message, Exception innerException)
59+
: base(message, innerException)
60+
{
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Exception that gets thrown if an authentication operation
66+
/// fails on the server.
67+
/// </summary>
68+
//[Serializable]
69+
public class AadAuthenticationFailedException : AadAuthenticationException
70+
{
71+
public AadAuthenticationFailedException(string message, Exception innerException) : base(message, innerException)
72+
{
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Exception thrown if a refresh token has expired.
78+
/// </summary>
79+
//[Serializable]
80+
public class AadAuthenticationCantRenewException : AadAuthenticationException
81+
{
82+
public AadAuthenticationCantRenewException()
83+
{
84+
}
85+
86+
public AadAuthenticationCantRenewException(string message) : base(message)
87+
{
88+
}
89+
90+
public AadAuthenticationCantRenewException(string message, Exception innerException) : base(message, innerException)
91+
{
92+
}
93+
}
94+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Rest;
16+
using System;
17+
using System.Net.Http;
18+
using System.Net.Http.Headers;
19+
using System.Threading;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Common.Authentication
23+
{
24+
public class AccessTokenCredential : ServiceClientCredentials
25+
{
26+
private readonly Guid subscriptionId;
27+
private readonly IAccessToken token;
28+
29+
public AccessTokenCredential(Guid subscriptionId, IAccessToken token)
30+
{
31+
this.subscriptionId = subscriptionId;
32+
this.token = token;
33+
this.TenantID = token.TenantId;
34+
}
35+
36+
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
37+
{
38+
token.AuthorizeRequest((tokenType, tokenValue) => {
39+
request.Headers.Authorization = new AuthenticationHeaderValue(tokenType, tokenValue);
40+
});
41+
return base.ProcessHttpRequestAsync(request, cancellationToken);
42+
}
43+
44+
public string SubscriptionId
45+
{
46+
get { return subscriptionId.ToString(); }
47+
}
48+
49+
public string TenantID { get; set; }
50+
}
51+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
16+
using System;
17+
18+
namespace Microsoft.Azure.Common.Authentication
19+
{
20+
/// <summary>
21+
/// Class storing the configuration information needed
22+
/// for ADAL to request token from the right AD tenant
23+
/// depending on environment.
24+
/// </summary>
25+
public class AdalConfiguration
26+
{
27+
//
28+
// These constants define the default values to use for AD authentication
29+
// against RDFE
30+
//
31+
public const string PowerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2";
32+
33+
public static readonly Uri PowerShellRedirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob");
34+
35+
// ID for site to pass to enable EBD (email-based differentiation)
36+
// This gets passed in the call to get the azure branding on the
37+
// login window. Also adding popup flag to handle overly large login windows.
38+
public const string EnableEbdMagicCookie = "site_id=501358&display=popup";
39+
40+
public string AdEndpoint { get;set; }
41+
42+
public bool ValidateAuthority { get; set; }
43+
44+
public string AdDomain { get; set; }
45+
46+
public string ClientId { get; set; }
47+
48+
public Uri ClientRedirectUri { get; set; }
49+
50+
public string ResourceClientUri { get; set; }
51+
52+
public TokenCache TokenCache { get; set; }
53+
54+
public AdalConfiguration()
55+
{
56+
ClientId = PowerShellClientId;
57+
ClientRedirectUri = PowerShellRedirectUri;
58+
ValidateAuthority = true;
59+
AdEndpoint = string.Empty;
60+
ResourceClientUri = "https://management.core.windows.net/";
61+
}
62+
}
63+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Common.Authentication.Models;
16+
using Microsoft.Azure.Common.Authentication.Properties;
17+
using System;
18+
19+
namespace Microsoft.Azure.Common.Authentication
20+
{
21+
/// <summary>
22+
/// A token provider that uses ADAL to retrieve
23+
/// tokens from Azure Active Directory
24+
/// </summary>
25+
public class AdalTokenProvider : ITokenProvider
26+
{
27+
private readonly ITokenProvider userTokenProvider;
28+
private readonly ITokenProvider servicePrincipalTokenProvider;
29+
30+
public AdalTokenProvider()
31+
{
32+
this.userTokenProvider = new UserTokenProvider();
33+
this.servicePrincipalTokenProvider = new ServicePrincipalTokenProvider();
34+
}
35+
36+
public IAccessToken GetAccessToken(
37+
AdalConfiguration config,
38+
ShowDialog promptBehavior,
39+
string userId,
40+
string password,
41+
AzureAccount.AccountType credentialType)
42+
{
43+
switch (credentialType)
44+
{
45+
case AzureAccount.AccountType.User:
46+
return userTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
47+
case AzureAccount.AccountType.ServicePrincipal:
48+
return servicePrincipalTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
49+
default:
50+
throw new ArgumentException(Resources.UnknownCredentialType, "credentialType");
51+
}
52+
}
53+
54+
public IAccessToken GetAccessTokenWithCertificate(
55+
AdalConfiguration config,
56+
string clientId,
57+
string certificate,
58+
string certificatePassword,
59+
AzureAccount.AccountType credentialType)
60+
{
61+
switch (credentialType)
62+
{
63+
case AzureAccount.AccountType.ServicePrincipal:
64+
return servicePrincipalTokenProvider.GetAccessTokenWithCertificate(
65+
config, clientId, certificate, certificatePassword, credentialType);
66+
default:
67+
throw new ArgumentException(string.Format(Resources.UnsupportedCredentialType, credentialType), "credentialType");
68+
}
69+
}
70+
}
71+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
17+
using Microsoft.Rest.Azure.Authentication;
18+
using System.Security;
19+
using System.Security.Cryptography.X509Certificates;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Common.Authentication
23+
{
24+
/// <summary>
25+
/// Interface to the certificate store for authentication
26+
/// </summary>
27+
internal sealed class CertificateApplicationCredentialProvider : IApplicationAuthenticationProvider
28+
{
29+
private string _certificateThumbprint;
30+
private string _certificatePassword;
31+
private Func<string, byte[]> _certificateMap;
32+
33+
/// <summary>
34+
/// Create a certificate provider
35+
/// </summary>
36+
/// <param name="certificateThumbprint"></param>
37+
/// <param name="certificatePassword"></param>
38+
/// <param name="certificateMap"></param>
39+
public CertificateApplicationCredentialProvider(string certificateThumbprint, string certificatePassword, Func<string, byte[]> certificateMap )
40+
{
41+
this._certificateThumbprint = certificateThumbprint;
42+
this._certificatePassword = certificatePassword;
43+
_certificateMap = certificateMap;
44+
}
45+
46+
/// <summary>
47+
/// Authenticate using certificate thumbprint from the datastore
48+
/// </summary>
49+
/// <param name="clientId">The active directory client id for the application.</param>
50+
/// <param name="audience">The intended audience for authentication</param>
51+
/// <param name="context">The AD AuthenticationContext to use</param>
52+
/// <returns></returns>
53+
public async Task<AuthenticationResult> AuthenticateAsync(
54+
string clientId,
55+
string audience,
56+
AuthenticationContext context)
57+
{
58+
var task = new Task<byte[]>(() =>
59+
{
60+
return _certificateMap(this._certificateThumbprint);
61+
});
62+
task.Start();
63+
var certificate = await task.ConfigureAwait(false);
64+
return await context.AcquireTokenAsync(
65+
audience,
66+
new ClientAssertionCertificate(clientId, certificate, this._certificatePassword));
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)