public TwoFactorDialogViewModel(
            IVisualStudioBrowser browser,
            ITwoFactorChallengeHandler twoFactorChallengeHandler)
        {
            Title = "Two-Factor authentication required";
            twoFactorChallengeHandler.SetViewModel(this);

            var canVerify = this.WhenAny(
                x => x.AuthenticationCode,
                x => x.IsBusy,
                (code, busy) => !string.IsNullOrEmpty(code.Value) && code.Value.Length == 6 && !busy.Value);

            OkCommand         = ReactiveCommand.Create(canVerify);
            CancelCommand     = ReactiveCommand.Create();
            NavigateLearnMore = ReactiveCommand.Create();
            NavigateLearnMore.Subscribe(x => browser.OpenUrl(GitHubUrls.TwoFactorLearnMore));
            //TODO: ShowHelpCommand.Subscribe(x => browser.OpenUrl(twoFactorHelpUri));
            ResendCodeCommand = ReactiveCommand.Create();

            showErrorMessage = this.WhenAny(
                x => x.IsAuthenticationCodeSent,
                x => x.InvalidAuthenticationCode,
                (authSent, invalid) => invalid.Value && !authSent.Value)
                               .ToProperty(this, x => x.ShowErrorMessage);

            description = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                          .Select(type =>
            {
                switch (type)
                {
                case TwoFactorType.Sms:
                    return("We sent you a message via SMS with your authentication code.");

                case TwoFactorType.AuthenticatorApp:
                    return("Open the two-factor authentication app on your device to view your " +
                           "authentication code.");

                case TwoFactorType.Unknown:
                    return("Enter a login authentication code here");

                default:
                    return(null);
                }
            })
                          .ToProperty(this, x => x.Description);

            isShowing = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                        .Select(factorType => factorType != TwoFactorType.None)
                        .ToProperty(this, x => x.IsShowing);

            isSms = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                    .Select(factorType => factorType == TwoFactorType.Sms)
                    .ToProperty(this, x => x.IsSms);
        }
        public TwoFactorDialogViewModel(
            IVisualStudioBrowser browser,
            ITwoFactorChallengeHandler twoFactorChallengeHandler)
        {
            Title = "Two-Factor authentication required";
            twoFactorChallengeHandler.SetViewModel(this);

            var canVerify = this.WhenAny(
                x => x.AuthenticationCode,
                x => x.IsBusy,
                (code, busy) => !string.IsNullOrEmpty(code.Value) && code.Value.Length == 6 && !busy.Value);

            OkCommand = ReactiveCommand.Create(canVerify);
            CancelCommand = ReactiveCommand.Create();
            NavigateLearnMore = ReactiveCommand.Create();
            NavigateLearnMore.Subscribe(x => browser.OpenUrl(GitHubUrls.TwoFactorLearnMore));
            //TODO: ShowHelpCommand.Subscribe(x => browser.OpenUrl(twoFactorHelpUri));
            ResendCodeCommand = ReactiveCommand.Create();

            showErrorMessage = this.WhenAny(
                x => x.IsAuthenticationCodeSent,
                x => x.InvalidAuthenticationCode,
                (authSent, invalid) => invalid.Value && !authSent.Value)
                .ToProperty(this, x => x.ShowErrorMessage);

            description = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                .Select(type =>
                {
                    switch (type)
                    {
                        case TwoFactorType.Sms:
                            return "We sent you a message via SMS with your authentication code.";
                        case TwoFactorType.AuthenticatorApp:
                            return "Open the two-factor authentication app on your device to view your " +
                                "authentication code.";
                        case TwoFactorType.Unknown:
                            return "Enter a login authentication code here";

                        default:
                            return null;
                    }
                })
                .ToProperty(this, x => x.Description);

            isShowing = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                .Select(factorType => factorType != TwoFactorType.None)
                .ToProperty(this, x => x.IsShowing);

            isSms = this.WhenAny(x => x.TwoFactorType, x => x.Value)
                .Select(factorType => factorType == TwoFactorType.Sms)
                .ToProperty(this, x => x.IsSms);
        }
Exemplo n.º 3
0
 public RepositoryHostFactory(
     IApiClientFactory apiClientFactory,
     IHostCacheFactory hostCacheFactory,
     ILoginCache loginCache,
     IAvatarProvider avatarProvider,
     ITwoFactorChallengeHandler twoFactorChallengeHandler)
 {
     this.apiClientFactory          = apiClientFactory;
     this.hostCacheFactory          = hostCacheFactory;
     this.loginCache                = loginCache;
     this.avatarProvider            = avatarProvider;
     this.twoFactorChallengeHandler = twoFactorChallengeHandler;
 }
 public RepositoryHostFactory(
     IApiClientFactory apiClientFactory,
     IHostCacheFactory hostCacheFactory,
     ILoginCache loginCache,
     IAvatarProvider avatarProvider,
     ITwoFactorChallengeHandler twoFactorChallengeHandler)
 {
     this.apiClientFactory = apiClientFactory;
     this.hostCacheFactory = hostCacheFactory;
     this.loginCache = loginCache;
     this.avatarProvider = avatarProvider;
     this.twoFactorChallengeHandler = twoFactorChallengeHandler;
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoginManager"/> class.
        /// </summary>
        /// <param name="loginCache">The cache in which to store login details.</param>
        /// <param name="twoFactorChallengeHandler">The handler for 2FA challenges.</param>
        /// <param name="clientId">The application's client API ID.</param>
        /// <param name="clientSecret">The application's client API secret.</param>
        /// <param name="authorizationNote">An note to store with the authorization.</param>
        /// <param name="fingerprint">The machine fingerprint.</param>
        public LoginManager(
            ILoginCache loginCache,
            ITwoFactorChallengeHandler twoFactorChallengeHandler,
            string clientId,
            string clientSecret,
            string authorizationNote = null,
            string fingerprint       = null)
        {
            Guard.ArgumentNotNull(loginCache, nameof(loginCache));
            Guard.ArgumentNotNull(twoFactorChallengeHandler, nameof(twoFactorChallengeHandler));
            Guard.ArgumentNotEmptyString(clientId, nameof(clientId));
            Guard.ArgumentNotEmptyString(clientSecret, nameof(clientSecret));

            this.loginCache = loginCache;
            this.twoFactorChallengeHandler = twoFactorChallengeHandler;
            this.clientId          = clientId;
            this.clientSecret      = clientSecret;
            this.authorizationNote = authorizationNote;
            this.fingerprint       = fingerprint;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoginManager"/> class.
        /// </summary>
        /// <param name="keychain">The keychain in which to store credentials.</param>
        /// <param name="twoFactorChallengeHandler">The handler for 2FA challenges.</param>
        /// <param name="clientId">The application's client API ID.</param>
        /// <param name="clientSecret">The application's client API secret.</param>
        /// <param name="authorizationNote">An note to store with the authorization.</param>
        /// <param name="fingerprint">The machine fingerprint.</param>
        public LoginManager(
            IKeychain keychain,
            ITwoFactorChallengeHandler twoFactorChallengeHandler,
            string clientId,
            string clientSecret,
            string authorizationNote = null,
            string fingerprint       = null)
        {
            Guard.ArgumentNotNull(keychain, nameof(keychain));
            Guard.ArgumentNotNull(twoFactorChallengeHandler, nameof(twoFactorChallengeHandler));
            Guard.ArgumentNotEmptyString(clientId, nameof(clientId));
            Guard.ArgumentNotEmptyString(clientSecret, nameof(clientSecret));

            this.keychain = keychain;
            this.twoFactorChallengeHandler = twoFactorChallengeHandler;
            this.clientId          = clientId;
            this.clientSecret      = clientSecret;
            this.authorizationNote = authorizationNote;
            this.fingerprint       = fingerprint;
        }