Skip to content
Snippets Groups Projects
Commit bb2d7f23 authored by Stanley Goldman's avatar Stanley Goldman
Browse files

Centralizing logout functionality

parent 33c8e369
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,16 @@ namespace GitHub.Unity
callback(repo);
}
public async void Logout(UriString host)
{
await LogoutInternal(host);
}
private async Task LogoutInternal(UriString host)
{
await loginManager.Logout(host);
}
public async Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result)
{
Guard.ArgumentNotNull(need2faCode, "need2faCode");
......
......@@ -13,5 +13,6 @@ namespace GitHub.Unity
Task ContinueLogin(LoginResult loginResult, string code);
Task<bool> LoginAsync(string username, string password, Func<LoginResult, string> need2faCode);
Task<bool> ValidateCredentials();
void Logout(UriString host);
}
}
......@@ -21,5 +21,12 @@ namespace GitHub.Unity
/// </exception>
Task<LoginResultData> Login(UriString host, IGitHubClient client, string username, string password);
Task<LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode);
/// <summary>
/// Logs out of GitHub server.
/// </summary>
/// <param name="hostAddress">The address of the server.</param>
/// <inheritdoc/>
Task Logout(UriString hostAddress);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ using System.Net;
using System.Threading.Tasks;
using Octokit;
using GitHub.Unity;
using Octokit_Extensions35;
namespace GitHub.Unity
{
......@@ -188,6 +189,14 @@ namespace GitHub.Unity
}
}
/// <inheritdoc/>
public async Task Logout(UriString hostAddress)
{
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
await new ActionTask(keychain.Clear(hostAddress, true)).StartAwait();
}
private async Task<ApplicationAuthorization> CreateAndDeleteExistingApplicationAuthorization(
IGitHubClient client,
NewAuthorization newAuth,
......
......@@ -223,10 +223,12 @@ namespace GitHub.Unity
}
private void SignOut(object obj)
{
var uriString = Platform.Keychain.Connections.First();
var host = Repository != null
? new UriString(Repository.CloneUrl.ToRepositoryUri().GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped))
: UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
new ActionTask(Platform.Keychain.Clear(uriString, true))
.Start();
var apiClient = ApiClient.Create(host, Platform.Keychain, new AppConfiguration());
apiClient.Logout(host);
}
private bool ValidateSettings()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment