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

Commit 41af06c

Browse files
Last fixes and tests for Keychain; Fix GitCredentialManager bug
1 parent 973c4e8 commit 41af06c

File tree

6 files changed

+228
-44
lines changed

6 files changed

+228
-44
lines changed

src/GitHub.Api/Authentication/ILoginManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,5 @@ interface ILoginManager
2121
/// </exception>
2222
Task<LoginResultData> Login(UriString host, IGitHubClient client, string username, string password);
2323
Task<LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode);
24-
25-
/// <summary>
26-
/// Logs out of GitHub server.
27-
/// </summary>
28-
/// <param name="hostAddress">The address of the server.</param>
29-
Task Logout(UriString hostAddress);
3024
}
3125
}

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ public async Task<IKeychainAdapter> Load(UriString host)
7272

7373
if (keychainItem == null)
7474
{
75+
logger.Warning("Cannot load host from credential manager; removing from cache");
7576
await Clear(host, false);
7677
}
7778
else
7879
{
79-
logger.Trace("Loading KeychainItem:{0}", keychainItem?.ToString() ?? "NULL");
80+
logger.Trace("Loading KeychainItem:{0}", keychainItem.ToString());
8081
keychainAdapter.Set(keychainItem);
8182
}
8283

@@ -201,16 +202,16 @@ public void SetCredentials(ICredential credential)
201202
{
202203
logger.Trace("SetCredentials Host:{0}", credential.Host);
203204

204-
var credentialAdapter = FindOrCreateAdapter(credential.Host);
205-
credentialAdapter.Set(credential);
205+
var keychainAdapter = keychainAdapters[credential.Host];
206+
keychainAdapter.Set(credential);
206207
}
207208

208209
public void SetToken(UriString host, string token)
209210
{
210211
logger.Trace("SetToken Host:{0}", host);
211212

212-
var credentialAdapter = FindOrCreateAdapter(host);
213-
credentialAdapter.UpdateToken(token);
213+
var keychainAdapter = keychainAdapters[host];
214+
keychainAdapter.UpdateToken(token);
214215
}
215216

216217
public void UpdateToken(UriString host, string token)

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public async Task<LoginResultData> Login(
7070

7171
// Start by saving the username and password, these will be used by the `IGitHubClient`
7272
// until an authorization token has been created and acquired:
73-
var keychainAdapter = keychain.Connect(host);
74-
var keychainItem = new Credential(host, username, password);
75-
keychain.SetCredentials(keychainItem);
73+
keychain.Connect(host);
74+
keychain.SetCredentials(new Credential(host, username, password));
7675

7776
var newAuth = new NewAuthorization
7877
{

src/GitHub.Api/Git/GitCredentialManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ public async Task<ICredential> Load(UriString host)
8585
return null;
8686
}
8787

88-
string user = null;
89-
dict.TryGetValue("user", out user);
88+
string user;
89+
if (!dict.TryGetValue("username", out user))
90+
{
91+
Logger.Error("No username is stored");
92+
return null;
93+
}
94+
9095
credential = new Credential(host, user, password);
9196
}
9297
return credential;

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void GoToProfile(object obj)
224224
private void SignOut(object obj)
225225
{
226226
var uriString = Platform.Keychain.Connections.First();
227-
227+
228228
new ActionTask(Platform.Keychain.Clear(uriString, true))
229229
.Start();
230230
}

0 commit comments

Comments
 (0)