public async Task <bool> ContinueLoginAsync(LoginResult loginResult, Func <LoginResult, string> need2faCode, string code) { LoginResultData result = null; try { result = await loginManager.ContinueLogin(loginResult.Data, code); } catch (Exception) { return(false); } if (result.Code == LoginResultCodes.CodeFailed) { var resultCache = new LoginResult(result, null, null); code = need2faCode(resultCache); if (String.IsNullOrEmpty(code)) { return(false); } return(await ContinueLoginAsync(resultCache, need2faCode, code)); } return(result.Code == LoginResultCodes.Success); }
public async Task Login(string username, string password, Action <LoginResult> need2faCode, Action <bool, string> result) { Guard.ArgumentNotNull(need2faCode, "need2faCode"); Guard.ArgumentNotNull(result, "result"); LoginResultData res = null; try { res = await loginManager.Login(OriginalUrl, githubClient, username, password); } catch (Exception ex) { logger.Warning(ex); result(false, ex.Message); return; } if (res.Code == LoginResultCodes.CodeRequired) { var resultCache = new LoginResult(res, result, need2faCode); need2faCode(resultCache); } else { result(res.Code == LoginResultCodes.Success, res.Message); } }
public LoginResultData ContinueLogin(LoginResultData loginResultData, string twofacode) { var host = loginResultData.Host; var keychainAdapter = keychain.Connect(host); var username = keychainAdapter.Credential.Username; var password = keychainAdapter.Credential.Token; try { loginResultData = TryLogin(host, username, password, twofacode); if (loginResultData.Code == LoginResultCodes.Success) { if (string.IsNullOrEmpty(loginResultData.Token)) { throw new InvalidOperationException("Returned token is null or empty"); } username = RetrieveUsername(loginResultData, username); keychain.SetToken(host, loginResultData.Token, username); keychain.Save(host); return(loginResultData); } return(loginResultData); } catch (Exception e) { logger.Warning(e, "Login Exception"); keychain.Clear(host, false); return(new LoginResultData(LoginResultCodes.Failed, Localization.LoginFailed, host)); } }
public async Task <bool> LoginAsync(string username, string password, Func <LoginResult, string> need2faCode) { Guard.ArgumentNotNull(need2faCode, "need2faCode"); LoginResultData res = null; try { res = await loginManager.Login(OriginalUrl, githubClient, username, password); } catch (Exception) { return(false); } if (res.Code == LoginResultCodes.CodeRequired) { var resultCache = new LoginResult(res, null, null); var code = need2faCode(resultCache); return(await ContinueLoginAsync(resultCache, need2faCode, code)); } else { return(res.Code == LoginResultCodes.Success); } }
public async Task <LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode) { var client = loginResultData.Client; var newAuth = loginResultData.NewAuth; var host = loginResultData.Host; try { logger.Trace("2FA Continue"); var auth = await CreateAndDeleteExistingApplicationAuthorization( client, newAuth, twofacode); EnsureNonNullAuthorization(auth); keychain.SetToken(host, auth.Token); await keychain.Save(host); return(new LoginResultData(LoginResultCodes.Success, "", host)); } catch (TwoFactorAuthorizationException e) { logger.Debug(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeFailed, e.Message); return(new LoginResultData(LoginResultCodes.CodeFailed, Localization.Wrong2faCode, client, host, newAuth)); } catch (ApiValidationException e) { logger.Debug(e, "2FA ApiValidationException: {0}", e.Message); var message = e.ApiError.FirstErrorMessageSafe(); await keychain.Clear(host, false); return(new LoginResultData(LoginResultCodes.Failed, message, host)); } catch (Exception e) { logger.Debug(e, "Exception: {0}", e.Message); await keychain.Clear(host, false); return(new LoginResultData(LoginResultCodes.Failed, e.Message, host)); } }
public async Task ContinueLogin(LoginResult loginResult, string code) { LoginResultData result = null; try { result = await loginManager.ContinueLogin(loginResult.Data, code); } catch (Exception ex) { loginResult.Callback(false, ex.Message); return; } if (result.Code == LoginResultCodes.CodeFailed) { loginResult.TwoFACallback(new LoginResult(result, loginResult.Callback, loginResult.TwoFACallback)); } loginResult.Callback(result.Code == LoginResultCodes.Success, result.Message); }
private async Task <string> RetrieveUsername(LoginResultData loginResultData, string username) { if (!username.Contains("@")) { return(username); } var octorunTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath.Value, octorunScript.Value, "validate", user: username, userToken: loginResultData.Token).Configure(processManager); var validateResult = await octorunTask.StartAsAsync(); if (!validateResult.IsSuccess) { throw new InvalidOperationException("Authentication validation failed"); } return(validateResult.Output[1]); }
private string RetrieveUsername(LoginResultData loginResultData, string username) { if (!username.Contains("@")) { return(username); } var octorunTask = new OctorunTask(taskManager.Token, keychain, environment, "validate") .Configure(processManager); var validateResult = octorunTask.RunSynchronously(); if (!validateResult.IsSuccess) { throw new InvalidOperationException("Authentication validation failed"); } return(validateResult.Output[1]); }
internal LoginResult(LoginResultData data, Action <bool, string> callback, Action <LoginResult> twofaCallback) { this.Data = data; this.Callback = callback; this.TwoFACallback = twofaCallback; }