예제 #1
0
        public SSOLoginViewModel(Action <string, string> openLoginForm) : base(false)
        {
            DisplaySignOnMode        = true;
            LoginWithDifferentMethod = ReactiveCommand.Create(() => openLoginForm(null, null));
            LoginAndLinkSSO          = ReactiveCommand.Create(() => openLoginForm(ConfirmationCode, Email));
            LoginCommand             = ReactiveCommand.Create(Login);
            BackToSSOLogin           = ReactiveCommand.Create(() => { DisplaySignOnMode = true; });
            var uriObservable = AuthUri.Where(uri => uri != null);

            uriObservable.Select(uri => HttpUtility.ParseQueryString(uri.Query).Get("apiToken"))
            .Where(token => !string.IsNullOrEmpty(token))
            .Subscribe(Toggl.LoginSSO);
            uriObservable.Select(uri => HttpUtility.ParseQueryString(uri.Query).Get("confirmation_code"))
            .ToPropertyEx(this, x => x.ConfirmationCode);
            uriObservable.Where(uri => HttpUtility.ParseQueryString(uri.Query).Get("apiToken") == null &&
                                HttpUtility.ParseQueryString(uri.Query).Get("confirmation_code") == null)
            .Subscribe(uri => Toggl.NewError("Single Sign On is not configured for your email address." +
                                             " Please try a different login method or contact your administrator.",
                                             true));
            this.WhenAnyValue(x => x.ConfirmationCode)
            .Where(code => !string.IsNullOrEmpty(code))
            .Subscribe(next => DisplaySignOnMode = false);
            Toggl.OnLoginSSO += HandleDisplayLoginSSO;
            _emailValidation  = this.ValidationRule(x => x.Email,
                                                    x => x == null || x.IsValidEmailAddress(), "Please enter a valid email");
        }
예제 #2
0
        public Uri ToUri()
        {
            StringBuilder builder = new StringBuilder(AuthUri.ToString());

            builder.Append($"?client_id={ClientId}");
            builder.Append($"&response_type={ResponseTypeParam.ToString().ToLower(CultureInfo.InvariantCulture)}");
            builder.Append($"&redirect_uri={HttpUtility.UrlEncode(RedirectUri.ToString())}");
            if (!string.IsNullOrEmpty(State))
            {
                builder.Append($"&state={HttpUtility.UrlEncode(State)}");
            }
            if (Scope != null)
            {
                builder.Append($"&scope={HttpUtility.UrlEncode(string.Join(" ", Scope))}");
            }
            if (ShowDialog != null)
            {
                builder.Append($"&show_dialog={ShowDialog.Value}");
            }

            return(new Uri(builder.ToString()));
        }