Skip to content

Commit

Permalink
MSAL cache env var should be interpreted as full file path (#434)
Browse files Browse the repository at this point in the history
MSAL cache changes to align with GCM removed ability to customize the
full file path for the MSAL cache. Addresses #432
  • Loading branch information
JohnSchmeichel authored Jul 12, 2023
1 parent ebafa53 commit cb98f0c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Authentication/MsalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static string DefaultMsalCacheLocation
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// The shared MSAL cache is located at "%LocalAppData%\.IdentityService\msal.cache" on Windows.
return Path.Combine(LocalAppDataLocation, ".IdentityService");
return Path.Combine(LocalAppDataLocation, ".IdentityService", "msal.cache");
}
else
{
// The shared MSAL cache metadata is located at "~/.local/.IdentityService/msal.cache" on UNIX.
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", ".IdentityService");
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", ".IdentityService", "msal.cache");
}
}
}
Expand All @@ -39,7 +39,8 @@ public static async Task<MsalCacheHelper> GetMsalCacheHelperAsync(string cacheLo

logger.LogTrace(Resources.MsalCacheLocation, cacheLocation);

const string cacheFileName = "msal.cache";
var fileName = Path.GetFileName(cacheLocation);
var directory = Path.GetDirectoryName(cacheLocation);

// Copied from GCM https://github.com/GitCredentialManager/git-credential-manager/blob/bdc20d91d325d66647f2837ffb4e2b2fe98d7e70/src/shared/Core/Authentication/MicrosoftAuthentication.cs#L371-L407
try
Expand Down Expand Up @@ -74,7 +75,7 @@ public static async Task<MsalCacheHelper> GetMsalCacheHelperAsync(string cacheLo

StorageCreationProperties CreateTokenCacheProperties(bool useLinuxFallback)
{
var builder = new StorageCreationPropertiesBuilder(cacheFileName, cacheLocation)
var builder = new StorageCreationPropertiesBuilder(fileName, directory)
.WithMacKeyChain("Microsoft.Developer.IdentityService", "MSALCache");

if (useLinuxFallback)
Expand All @@ -84,7 +85,7 @@ StorageCreationProperties CreateTokenCacheProperties(bool useLinuxFallback)
else
{
// The SecretService/keyring is used on Linux with the following collection name and attributes
builder.WithLinuxKeyring(cacheFileName,
builder.WithLinuxKeyring(fileName,
"default", "MSALCache",
new KeyValuePair<string, string>("MsalClientID", "Microsoft.Developer.IdentityService"),
new KeyValuePair<string, string>("Microsoft.Developer.IdentityService", "1.0.0.0"));
Expand Down

0 comments on commit cb98f0c

Please sign in to comment.