Skip to content

Commit 49ca302

Browse files
committed
msauth: include better warning message on Keychain errors
Sometimes the login Keychain is not accessible and the MSAL.Extensions library cannot read/write the token cache. The specific error encountered internally is `errSecAuthFailed` - neither we nor the MSAL team know why this happens sometimes. Locking and then unlocking the login Keychain manually, or simply restarting the computer appears to fix the problem. Include the lock+unlock/restart remedy in the warning message on macOS.
1 parent 3c3ae22 commit 49ca302

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/shared/Microsoft.Git.CredentialManager/Authentication/MicrosoftAuthentication.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,23 @@ private async Task RegisterTokenCacheAsync(IPublicClientApplication app)
236236
}
237237
catch (MsalCachePersistenceException ex)
238238
{
239-
Context.Streams.Error.WriteLine("warning: cannot persist Microsoft Authentication data securely!");
239+
Context.Streams.Error.WriteLine("warning: cannot persist Microsoft authentication token cache securely!");
240240
Context.Trace.WriteLine("Cannot persist Microsoft Authentication data securely!");
241241
Context.Trace.WriteException(ex);
242242

243-
// On Linux the SecretService/keyring might not be available so we must fall-back to a plaintext file.
244-
if (PlatformUtils.IsLinux())
243+
if (PlatformUtils.IsMacOS())
245244
{
245+
// On macOS sometimes the Keychain returns the "errSecAuthFailed" error - we don't know why
246+
// but it appears to be something to do with not being able to access the keychain.
247+
// Locking and unlocking (or restarting) often fixes this.
248+
Context.Streams.Error.WriteLine(
249+
"warning: there is a problem accessing the login Keychain - either manually lock and unlock the " +
250+
"login Keychain, or restart the computer to remedy this");
251+
}
252+
else if (PlatformUtils.IsLinux())
253+
{
254+
// On Linux the SecretService/keyring might not be available so we must fall-back to a plaintext file.
255+
Context.Streams.Error.WriteLine("warning: using plain-text fallback token cache");
246256
Context.Trace.WriteLine("Using fall-back plaintext token cache on Linux.");
247257
var storageProps = CreateTokenCacheProps(clientId, useLinuxFallback: true);
248258
helper = await MsalCacheHelper.CreateAsync(storageProps);

0 commit comments

Comments
 (0)