Skip to content

Commit 6f6aa32

Browse files
erich-wangcormacpaynexiaohuyyyy-msisra-felmsJinLei
authored
Add support for Azure.Identity integration (#218)
* Add method needed to get TokenCache for MSAL * Change name of cache to "msal.cache" * Add event to allow writing to various streams * Update Dependencies.Test.targets * Update Dependencies.Test.targets * change the deprecated licenseUrl element to license file instead * change the deprecated licenseUrl element to using license file link instead * Resolve review feedback * fix no default context * add a property 'environment' to AzureSession * Disable context auto saving when AzureRmContext.json not available Fix the issue Azure/azure-powershell#8963 Enable warning messages printout in module importing. * Add EnqueueDebugMessage * Add az version, time, and subscription id to client telemetry * Catch exception if host is not available * change require default context method * add support for Azure.Identity integration * use right default tenant Co-authored-by: cormacpayne <[email protected]> Co-authored-by: xiaohuyyyy-ms <[email protected]> Co-authored-by: Yeming Liu <[email protected]> Co-authored-by: msJinLei <[email protected]> Co-authored-by: Dingmeng Xue <[email protected]>
1 parent c091c90 commit 6f6aa32

30 files changed

+299
-41
lines changed

Azure.PowerShell.Common.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29613.14
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.1231
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "src\Common\Common.csproj", "{5EE72C53-1720-4309-B54B-5FB79703195F}"
77
EndProject

src/Aks/Aks.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageTags>azure;powershell;clients;aks</PackageTags>
1818
<Authors>Microsoft Corporation</Authors>
1919
<Copyright>Copyright © Microsoft Corporation</Copyright>
20-
<PackageLicenseUrl>https://aka.ms/azps-common-license</PackageLicenseUrl>
20+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2121
<PackageProjectUrl>https://github.com/Azure/azure-powershell-common</PackageProjectUrl>
2222
<PackageOutputPath>$(ProjectDir)..\..\artifacts\Package\$(Configuration)</PackageOutputPath>
2323
</PropertyGroup>
@@ -49,4 +49,8 @@
4949
</EmbeddedResource>
5050
</ItemGroup>
5151

52+
<ItemGroup>
53+
<None Include="..\..\LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="" />
54+
</ItemGroup>
55+
5256
</Project>

src/Authentication.Abstractions/Authentication.Abstractions.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageTags>azure;powershell;authentication;abstractions</PackageTags>
2121
<Authors>Microsoft Corporation</Authors>
2222
<Copyright>Copyright © Microsoft Corporation</Copyright>
23-
<PackageLicenseUrl>https://aka.ms/azps-common-license</PackageLicenseUrl>
23+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2424
<PackageProjectUrl>https://github.com/Azure/azure-powershell-common</PackageProjectUrl>
2525
<PackageOutputPath>$(ProjectDir)..\..\artifacts\Package\$(Configuration)</PackageOutputPath>
2626
</PropertyGroup>
@@ -53,6 +53,7 @@
5353
</ItemGroup>
5454

5555
<ItemGroup>
56+
<None Include="..\..\LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="" />
5657
<Folder Include="Models\" />
5758
</ItemGroup>
5859

src/Authentication.Abstractions/AuthenticationStore.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
2020
/// State storage for token cache
2121
/// </summary>
2222
[Serializable]
23-
public class AzureTokenCache : IAzureTokenCache
23+
public class AzureTokenCache : IAzureTokenCache, IAzureMsalTokenCache
2424
{
2525
/// <summary>
2626
/// Token Cache serialization
2727
/// </summary>
2828
public virtual byte[] CacheData {get; set;}
2929

30+
/// <summary>
31+
/// Get the user token cache.
32+
/// </summary>
33+
public object GetUserCache()
34+
{
35+
return null;
36+
}
37+
3038
/// <summary>
3139
/// Remove all token cache state
3240
/// </summary>

src/Authentication.Abstractions/AzureAccount.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ public static class Property
105105
/// </summary>
106106
AccessToken = "AccessToken",
107107

108+
/// <summary>
109+
/// Account object id + home tenant id.
110+
/// </summary>
111+
HomeAccountId = "HomeAccountId",
112+
113+
/// <summary>
114+
/// Indicate whether to use user name and password for authentication.
115+
/// </summary>
116+
UsePasswordAuth = "UsePasswordAuth",
117+
108118
/// <summary>
109119
/// Access token for AD Graph service.
110120
/// </summary>

src/Authentication.Abstractions/AzureSession.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void ClearComponents()
254254

255255
void ChangeRegistry(Action changeAction)
256256
{
257-
changeAction();
257+
changeAction();
258258
}
259259

260260
private class ComponentKey : IComparable<ComponentKey>, IEquatable<ComponentKey>
@@ -341,5 +341,13 @@ public int GetHashCode(ComponentKey obj)
341341
return obj.GetHashCode();
342342
}
343343
}
344+
345+
public static class Property
346+
{
347+
/// <summary>
348+
/// Name of the current environment
349+
/// </summary>
350+
public const string Environment = "Environment";
351+
}
344352
}
345353
}

src/Authentication.Abstractions/Extensions/AzureAccountExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public static void Update(this IAzureAccount account, IAzureAccount source)
231231
/// <param name="account">The account to get tenant from</param>
232232
public static string GetCommonTenant(this IAzureAccount account)
233233
{
234-
string result = AzureEnvironmentConstants.CommonAdTenant;
234+
string result = "organizations";
235235
if (account.IsPropertySet(AzureAccount.Property.Tenants))
236236
{
237237
var candidate = account.GetTenants().FirstOrDefault();

src/Authentication.Abstractions/Interfaces/IAccessToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
using System;
1616

17+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
18+
1719
namespace Microsoft.Azure.Commands.Common.Authentication
1820
{
1921
/// <summary>
2022
/// Canonical representation of a renewable access token
2123
/// </summary>
22-
public interface IAccessToken
24+
public interface IAccessToken : IExtensibleModel
2325
{
2426
/// <summary>
2527
/// Authorize the given request, using the given function for setting the token
@@ -37,6 +39,11 @@ public interface IAccessToken
3739
/// </summary>
3840
string UserId { get; }
3941

42+
/// <summary>
43+
/// The object id + home tenant id
44+
/// </summary>
45+
string HomeAccountId { get; }
46+
4047
/// <summary>
4148
/// The Active Directory tenant for this token
4249
/// </summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.Commands.Common.Authentication.Abstractions
18+
{
19+
public interface IAzureEventListener : IDisposable
20+
{
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.Commands.Common.Authentication.Abstractions
18+
{
19+
public interface IAzureEventListenerFactory
20+
{
21+
IAzureEventListener GetAzureEventListener(Action<string> action);
22+
}
23+
}

0 commit comments

Comments
 (0)