Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 6ac6be4

Browse files
Throwing exception from LoadKeychainInternal
- LoadKeychainInternal is only called from ValidateKeychain - ValidateKeychain should throw a TokenUsernameMismatchException if it can see the user does not match
1 parent 8ccf997 commit 6ac6be4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,19 @@ private async Task<bool> LoadKeychainInternal()
379379
logger.Trace("LoadKeychainInternal: Loading");
380380

381381
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
382-
var uriString = keychain.Connections.First().Host;
382+
var connection = keychain.Connections.First();
383+
var uriString = connection.Host;
383384

384385
var keychainAdapter = await keychain.Load(uriString);
385386
logger.Trace("LoadKeychainInternal: Loaded");
386387

387-
return keychainAdapter.Credential.Token != null;
388+
var keychainUsername = keychainAdapter.Credential?.Username;
389+
if (keychainUsername == null || connection.Username != keychainUsername)
390+
{
391+
throw new TokenUsernameMismatchException(connection.Username, keychainUsername);
392+
}
393+
394+
return keychainAdapter.Credential?.Token != null;
388395
}
389396

390397
logger.Trace("LoadKeychainInternal: No keys to load");

0 commit comments

Comments
 (0)