Skip to content

Commit 293204e

Browse files
authored
Merge pull request #305 from mjcheetham/osx-msal-restartmsg
Include better warning message on MSAL Keychain errors
2 parents 3c3ae22 + 49ca302 commit 293204e

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)