Пример #1
0
        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);
        }
Пример #2
0
 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)));
        }
Пример #6
0
 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;
 }
Пример #7
0
        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);
        }
Пример #8
0
        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;
        }
Пример #9
0
 public bool RemoveConnection(HostAddress address)
 {
     var c = Connections.FirstOrDefault(x => x.HostAddress.Equals(address));
     if (c == null)
         return false;
     RequestLogout(c);
     return true;
 }
Пример #10
0
 public bool RemoveConnection(HostAddress address)
 {
     var c = Connections.FirstOrDefault(x => x.HostAddress == address);
     if (c == null)
         return false;
     Connections.Remove(c);
     return true;
 }
Пример #11
0
 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;
 }
Пример #12
0
 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);
 }
Пример #13
0
 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;
 }
Пример #14
0
        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));
                }
            });
        }
Пример #15
0
 public IObservable<Unit> EraseLogin(HostAddress hostAddress)
 {
     return loginCacheDelegate.EraseLogin(hostAddress);
 }
Пример #16
0
 public IObservable<Unit> SaveLogin(string user, string password, HostAddress hostAddress)
 {
     return loginCacheDelegate.SaveLogin(user, password, hostAddress);
 }
Пример #17
0
 public IObservable<LoginInfo> GetLoginAsync(HostAddress hostAddress)
 {
     return loginCacheDelegate.GetLoginAsync(hostAddress);
 }
Пример #18
0
 IConnection SetupConnection(HostAddress address, string username)
 {
     var conn = new Connection(this, address, username);
     return conn;
 }
Пример #19
0
 /// <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;
             }
         });
 }
Пример #20
0
 public IConnection CreateConnection(HostAddress address, string username)
 {
     return SetupConnection(address, username);
 }
 public SimpleCredentialStore(HostAddress hostAddress)
 {
     this.hostAddress = hostAddress;
 }
Пример #22
0
 public Connection(IConnectionManager cm, HostAddress hostAddress, string userName)
 {
     manager = cm;
     HostAddress = hostAddress;
     Username = userName;
 }
Пример #23
0
        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));
                    }
                });
        }
Пример #24
0
 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);
             }
         });
 }
Пример #25
0
 public IObservable<LoginInfo> GetLoginAsync(HostAddress hostAddress)
 {
     return cache.Secure.GetLoginAsync(hostAddress.CredentialCacheKeyHost)
         .Catch<LoginInfo, Exception>(e => Observable.Return(empty));
 }
Пример #26
0
 public ApiClient(HostAddress hostAddress, IObservableGitHubClient gitHubClient)
 {
     Configure();
     HostAddress = hostAddress;
     this.gitHubClient = gitHubClient;
 }
Пример #27
0
 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;
 }
Пример #29
0
 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));
         }
     });
 }