Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Accounts/Authentication/Authentication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.8.1" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.6.0-preview" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.7.0-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Internal.Subscriptions;
using Microsoft.Azure.Internal.Subscriptions.Models;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
using Microsoft.Rest;
using Microsoft.WindowsAzure.Commands.Common;
using System;
Expand All @@ -35,7 +34,6 @@ public abstract class AuthenticationClientFactory
public static readonly string AuthenticationClientFactoryKey = nameof(AuthenticationClientFactory);
protected readonly string PowerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2";
private static readonly string CommonTenant = "organizations";
private static readonly object _lock = new object();

protected byte[] _tokenCacheDataToFlush;

Expand Down Expand Up @@ -256,43 +254,5 @@ private SubscriptionClient GetSubscriptionClient(IAccessToken token, IAzureEnvir
new TokenCredentials(token.AccessToken) as ServiceClientCredentials,
AzureSession.Instance.ClientFactory.GetCustomHandlers());
}

protected byte[] TryReadTokenFromFileCache(string cacheFilePath)
{
byte[] data = null;
lock (_lock)
{
try
{
var cacheStorage = GetCacheStorage(cacheFilePath);
data = cacheStorage.ReadData();
}
catch { }
}
return data;
}

protected void WriteTokenToFileCache(byte[] data, string cacheFilePath)
{
lock (_lock)
{
var cacheStorage = GetCacheStorage(cacheFilePath);
cacheStorage.WriteData(data);
}
}

private MsalCacheStorage GetCacheStorage(string filePath)
{
var builder = new StorageCreationPropertiesBuilder(Path.GetFileName(filePath), Path.GetDirectoryName(filePath), PowerShellClientId);
builder = builder.WithMacKeyChain(serviceName: "Microsoft.Developer.IdentityService", accountName: "MSALCache");
builder = builder.WithLinuxKeyring(
schemaName: "msal.cache",
collection: "default",
secretLabel: "MSALCache",
attribute1: new KeyValuePair<string, string>("MsalClientID", "Microsoft.Developer.IdentityService"),
attribute2: new KeyValuePair<string, string>("MsalClientVersion", "1.0.0.0"));
var storageCreationProperties = builder.Build();
return MsalCacheStorage.Create(storageCreationProperties, new TraceSource("Azure PowerShell"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class SharedTokenCacheClientFactory : AuthenticationClientFactory

public override byte[] ReadTokenData()
{
return TryReadTokenFromFileCache(CacheFilePath);
return GetCacheHelper(PowerShellClientId).LoadUnencryptedTokenCache();
}

public override void FlushTokenData()
{
WriteTokenToFileCache(_tokenCacheDataToFlush, CacheFilePath);
GetCacheHelper(PowerShellClientId).SaveUnencryptedTokenCache(_tokenCacheDataToFlush);
base.FlushTokenData();
}

Expand Down
Binary file not shown.
Binary file not shown.