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

Commit bb2d7f2

Browse files
Centralizing logout functionality
1 parent 33c8e36 commit bb2d7f2

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

src/GitHub.Api/Api/ApiClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public async void GetRepository(Action<Octokit.Repository> callback)
4949
callback(repo);
5050
}
5151

52+
public async void Logout(UriString host)
53+
{
54+
await LogoutInternal(host);
55+
}
56+
57+
private async Task LogoutInternal(UriString host)
58+
{
59+
await loginManager.Logout(host);
60+
}
61+
5262
public async Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result)
5363
{
5464
Guard.ArgumentNotNull(need2faCode, "need2faCode");

src/GitHub.Api/Api/IApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ interface IApiClient
1313
Task ContinueLogin(LoginResult loginResult, string code);
1414
Task<bool> LoginAsync(string username, string password, Func<LoginResult, string> need2faCode);
1515
Task<bool> ValidateCredentials();
16+
void Logout(UriString host);
1617
}
1718
}

src/GitHub.Api/Authentication/ILoginManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ 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+
/// <inheritdoc/>
30+
Task Logout(UriString hostAddress);
2431
}
2532
}

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Octokit;
55
using GitHub.Unity;
6+
using Octokit_Extensions35;
67

78
namespace GitHub.Unity
89
{
@@ -188,6 +189,14 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
188189
}
189190
}
190191

192+
/// <inheritdoc/>
193+
public async Task Logout(UriString hostAddress)
194+
{
195+
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
196+
197+
await new ActionTask(keychain.Clear(hostAddress, true)).StartAwait();
198+
}
199+
191200
private async Task<ApplicationAuthorization> CreateAndDeleteExistingApplicationAuthorization(
192201
IGitHubClient client,
193202
NewAuthorization newAuth,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ private void GoToProfile(object obj)
223223
}
224224
private void SignOut(object obj)
225225
{
226-
var uriString = Platform.Keychain.Connections.First();
226+
var host = Repository != null
227+
? new UriString(Repository.CloneUrl.ToRepositoryUri().GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped))
228+
: UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
227229

228-
new ActionTask(Platform.Keychain.Clear(uriString, true))
229-
.Start();
230+
var apiClient = ApiClient.Create(host, Platform.Keychain, new AppConfiguration());
231+
apiClient.Logout(host);
230232
}
231233

232234
private bool ValidateSettings()

0 commit comments

Comments
 (0)