public IObservable<Unit> SaveLogin(string user, string password, HostAddress hostAddress) { Guard.ArgumentNotEmptyString(user, nameof(user)); Guard.ArgumentNotEmptyString(password, nameof(password)); return cache.Secure.SaveLogin(user, password, hostAddress.CredentialCacheKeyHost); }
public Connection(IConnectionManager cm, HostAddress hostAddress, string userName) { manager = cm; HostAddress = hostAddress; Username = userName; Repositories = new ObservableCollection<ISimpleRepositoryModel>(); }
public static IObservable<bool> IsLoggedIn(this IConnectionManager cm, IRepositoryHosts hosts, HostAddress address) { return cm.Connections.ToObservable() .Where(c => c.HostAddress.Equals(address)) .SelectMany(c => c.Login()) .Any(c => hosts.LookupHost(c.HostAddress).IsLoggedIn); }
public IRepositoryHost Create(HostAddress hostAddress) { var apiClient = apiClientFactory.Create(hostAddress); var hostCache = hostCacheFactory.Create(hostAddress); var modelService = new ModelService(apiClient, hostCache, avatarProvider); return new RepositoryHost(apiClient, modelService, loginCache, twoFactorChallengeHandler); }
public IApiClient Create(HostAddress hostAddress) { var apiBaseUri = hostAddress.ApiUri; return new ApiClient( hostAddress, new ObservableGitHubClient(new GitHubClient(productHeader, new GitHubCredentialStore(hostAddress, LoginCache), apiBaseUri))); }
internal SimpleApiClient(HostAddress hostAddress, Uri repoUrl, GitHubClient githubClient, Lazy<IEnterpriseProbeTask> enterpriseProbe, Lazy<IWikiProbe> wikiProbe) { HostAddress = hostAddress; OriginalUrl = repoUrl; client = githubClient; this.enterpriseProbe = enterpriseProbe; this.wikiProbe = wikiProbe; }
public IBlobCache Create(HostAddress hostAddress) { var environment = OperatingSystem.Environment; // For GitHub.com, the cache file name should be "api.github.com.cache.db" // This is why we use ApiUrl and not CredentialCacheHostKey string host = hostAddress.ApiUri.Host; string cacheFileName = host + ".cache.db"; var userAccountPath = Path.Combine(environment.GetApplicationDataPath(), cacheFileName); // CreateDirectory is a noop if the directory already exists. OperatingSystem.Directory.CreateDirectory(Path.GetDirectoryName(userAccountPath)); return BlobCacheFactory.CreateBlobCache(userAccountPath); }
public RepositoryHost( IApiClient apiClient, IModelService modelService, ILoginCache loginCache, ITwoFactorChallengeHandler twoFactorChallengeHandler) { ApiClient = apiClient; ModelService = modelService; this.loginCache = loginCache; this.twoFactorChallengeHandler = twoFactorChallengeHandler; Debug.Assert(apiClient.HostAddress != null, "HostAddress of an api client shouldn't be null"); Address = apiClient.HostAddress; hostAddress = apiClient.HostAddress; isEnterprise = !hostAddress.IsGitHubDotCom(); Title = apiClient.HostAddress.Title; }
public bool RemoveConnection(HostAddress address) { var c = Connections.FirstOrDefault(x => x.HostAddress.Equals(address)); if (c == null) return false; RequestLogout(c); return true; }
public bool RemoveConnection(HostAddress address) { var c = Connections.FirstOrDefault(x => x.HostAddress == address); if (c == null) return false; Connections.Remove(c); return true; }
public bool AddConnection(HostAddress address, string username) { if (Connections.FirstOrDefault(x => x.HostAddress == address) != null) return false; Connections.Add(new Connection(this, address, username)); return true; }
public IObservable<Unit> EraseLogin(HostAddress hostAddress) { log.Info(CultureInfo.CurrentCulture, "Erasing the git credential cache for host '{0}'", hostAddress.CredentialCacheKeyHost); return cache.Secure.EraseLogin(hostAddress.CredentialCacheKeyHost); }
public bool AddConnection(HostAddress address, string username) { if (Connections.FirstOrDefault(x => x.HostAddress.Equals(address)) != null) return false; Connections.Add(SetupConnection(address, username)); return true; }
protected IObservable<AuthenticationResult> LogInToHost(HostAddress hostAddress) { return Observable.Defer(() => { ShowLogInFailedError = false; ShowConnectingToHostFailed = false; return hostAddress != null ? RepositoryHosts.LogIn(hostAddress, UsernameOrEmail, Password) : Observable.Return(AuthenticationResult.CredentialFailure); }) .ObserveOn(RxApp.MainThreadScheduler) .Do(authResult => { switch (authResult) { case AuthenticationResult.CredentialFailure: ShowLogInFailedError = true; break; case AuthenticationResult.VerificationFailure: break; case AuthenticationResult.EnterpriseServerNotFound: ShowConnectingToHostFailed = true; break; } }) .SelectMany(authResult => { switch (authResult) { case AuthenticationResult.CredentialFailure: case AuthenticationResult.EnterpriseServerNotFound: case AuthenticationResult.VerificationFailure: Password = ""; return Observable.FromAsync(PasswordValidator.ResetAsync) .Select(_ => AuthenticationResult.CredentialFailure); case AuthenticationResult.Success: return Reset.ExecuteAsync() .ContinueAfter(() => Observable.Return(AuthenticationResult.Success)); default: return Observable.Throw<AuthenticationResult>( new InvalidOperationException("Unknown EnterpriseLoginResult: " + authResult)); } }); }
public IObservable<Unit> EraseLogin(HostAddress hostAddress) { return loginCacheDelegate.EraseLogin(hostAddress); }
public IObservable<Unit> SaveLogin(string user, string password, HostAddress hostAddress) { return loginCacheDelegate.SaveLogin(user, password, hostAddress); }
public IObservable<LoginInfo> GetLoginAsync(HostAddress hostAddress) { return loginCacheDelegate.GetLoginAsync(hostAddress); }
IConnection SetupConnection(HostAddress address, string username) { var conn = new Connection(this, address, username); return conn; }
/// <summary> /// This is only called by the connection manager when logging in connections /// that already exist so we don't have to add the connection. /// </summary> /// <param name="address"></param> /// <returns></returns> public IObservable<AuthenticationResult> LogInFromCache(HostAddress address) { var isDotCom = HostAddress.GitHubDotComHostAddress == address; var host = RepositoryHostFactory.Create(address); disposables.Add(host); return host.LogInFromCache() .Catch<AuthenticationResult, Exception>(Observable.Throw<AuthenticationResult>) .Do(result => { bool successful = result.IsSuccess(); if (successful) { if (isDotCom) GitHubHost = host; else EnterpriseHost = host; } }); }
public IConnection CreateConnection(HostAddress address, string username) { return SetupConnection(address, username); }
public SimpleCredentialStore(HostAddress hostAddress) { this.hostAddress = hostAddress; }
public Connection(IConnectionManager cm, HostAddress hostAddress, string userName) { manager = cm; HostAddress = hostAddress; Username = userName; }
public IObservable<AuthenticationResult> LogIn( HostAddress address, string usernameOrEmail, string password) { var isDotCom = HostAddress.GitHubDotComHostAddress == address; var host = RepositoryHostFactory.Create(address); return host.LogIn(usernameOrEmail, password) .Catch<AuthenticationResult, Exception>(Observable.Throw<AuthenticationResult>) .Do(result => { bool successful = result.IsSuccess(); log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}", address.ApiUri, usernameOrEmail, successful ? "SUCCEEDED" : "FAILED", isDotCom ? "GitHub.com" : address.WebUri.Host ); if (successful) { // Make sure that GitHubHost/EnterpriseHost are set when the connections // changed event is raised and likewise that the connection is added when // the property changed notification is sent. if (isDotCom) githubHost = host; else enterpriseHost = host; connectionManager.AddConnection(address, usernameOrEmail); if (isDotCom) this.RaisePropertyChanged(nameof(GitHubHost)); else this.RaisePropertyChanged(nameof(EnterpriseHost)); } }); }
public IObservable<AuthenticationResult> LogIn( HostAddress address, string usernameOrEmail, string password) { var isDotCom = HostAddress.GitHubDotComHostAddress == address; var host = RepositoryHostFactory.Create(address); disposables.Add(host); return host.LogIn(usernameOrEmail, password) .Catch<AuthenticationResult, Exception>(Observable.Throw<AuthenticationResult>) .Do(result => { bool successful = result.IsSuccess(); log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}", address.ApiUri, usernameOrEmail, successful ? "SUCCEEDED" : "FAILED", isDotCom ? "GitHub.com" : address.WebUri.Host ); if (successful) { if (isDotCom) GitHubHost = host; else EnterpriseHost = host; connectionManager.AddConnection(address, usernameOrEmail); } }); }
public IObservable<LoginInfo> GetLoginAsync(HostAddress hostAddress) { return cache.Secure.GetLoginAsync(hostAddress.CredentialCacheKeyHost) .Catch<LoginInfo, Exception>(e => Observable.Return(empty)); }
public ApiClient(HostAddress hostAddress, IObservableGitHubClient gitHubClient) { Configure(); HostAddress = hostAddress; this.gitHubClient = gitHubClient; }
public IConnection CreateConnection(HostAddress address, string username) { return new Connection(this, address, username); }
public GitHubCredentialStore(HostAddress hostAddress, ILoginCache loginCache) { this.hostAddress = hostAddress; this.loginCache = loginCache; }
protected IObservable<AuthenticationResult> LogInToHost(HostAddress hostAddress) { return Observable.Defer(() => { return hostAddress != null ? RepositoryHosts.LogIn(hostAddress, UsernameOrEmail, Password) : Observable.Return(AuthenticationResult.CredentialFailure); }) .ObserveOn(RxApp.MainThreadScheduler) .Do(authResult => { switch (authResult) { case AuthenticationResult.CredentialFailure: UserError.Throw(new UserError( Resources.LoginFailedText, Resources.LoginFailedMessage, new[] { NavigateForgotPassword })); break; case AuthenticationResult.VerificationFailure: break; case AuthenticationResult.EnterpriseServerNotFound: UserError.Throw(new UserError(Resources.CouldNotConnectToGitHub)); break; } }) .SelectMany(authResult => { switch (authResult) { case AuthenticationResult.CredentialFailure: case AuthenticationResult.EnterpriseServerNotFound: case AuthenticationResult.VerificationFailure: Password = ""; return Observable.FromAsync(PasswordValidator.ResetAsync) .Select(_ => AuthenticationResult.CredentialFailure); case AuthenticationResult.Success: return Reset.ExecuteAsync() .ContinueAfter(() => Observable.Return(AuthenticationResult.Success)); default: return Observable.Throw<AuthenticationResult>( new InvalidOperationException("Unknown EnterpriseLoginResult: " + authResult)); } }); }