Exemplo n.º 1
0
 public async Task<IActionResult> AuthResult(AuthResultAddressModel model)
 {
     if (!User.Identity.IsAuthenticated && ModelState.IsValid)
     {
         await AuthProcess.AuthApp(this, model, _userManager, _signInManager);
     }
     return Redirect(model.state);
 }
Exemplo n.º 2
0
        //async Task<bool> SetTokenToMainApp(string token)
        //{
        //    if (!await ConnectionService._connection.GetConnection()) return false;

        //    var message = new ValueSet();
        //    message.Add("Type", "COMMON");
        //    message.Add("Command", "SETNESTTOKEN");
        //    message.Add("NESTTOKEN", token);

        //    AppServiceResponse response = await ConnectionService._connection.connection.SendMessageAsync(message);

        //    return true;
        //}


        async void Login(object button)
        {
            (button as Button).Focus(FocusState.Pointer);

            if (string.IsNullOrEmpty(ViewModel.ProductID))
            {
                ViewModel.IDBrush = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x41, 0x41));
                return;
            }

            if (string.IsNullOrEmpty(ViewModel.ProductSecret))
            {
                ViewModel.SecretBrush = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x41, 0x41));
                return;
            }

            if (string.IsNullOrEmpty(ViewModel.AuthorizationURL) || false == ViewModel.AuthorizationURL.Contains("https://home.nest.com/login/oauth2?client_id="))
            {
                ViewModel.URLBrush = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x41, 0x41));
                return;
            }

            Global.Instance.SetAuthValue(ViewModel.ProductID, ViewModel.ProductSecret, ViewModel.AuthorizationURL);

            Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            localSettings.Values["ProductID"]        = ViewModel.ProductID;
            localSettings.Values["ProductSecret"]    = ViewModel.ProductSecret;
            localSettings.Values["AuthorizationURL"] = ViewModel.AuthorizationURL;

            await Windows.UI.Xaml.Controls.WebView.ClearTemporaryWebDataAsync();

            ViewModel.SettingView     = false;
            ViewModel.AuthProcessView = true;

            AuthProcess.Navigate(new Uri(Global.Instance.AuthorizationURL));
        }
Exemplo n.º 3
0
        private void ShowLoginInternal(bool canChangeUrl, Action onSuccess = null)
        {
            var config = _appConfigStorage.Load();

            AuthProcess.Start(
                getAuthenticationData: async() =>
            {
                var view = (Application.Current.MainWindow as MetroWindow);

                LoginWithUrlDialogSettings settings = new LoginWithUrlDialogSettings
                {
                    AnimateShow              = true,
                    AnimateHide              = true,
                    AffirmativeButtonText    = "Login",
                    NegativeButtonText       = "Exit",
                    NegativeButtonVisibility = Visibility.Visible,
                    UrlWatermark             = "Url",
                    ShouldHideUrl            = !canChangeUrl,
                    InitialUrl                 = config.HostUrl,
                    EmailWatermark             = "*****@*****.**",
                    PhoneWatermark             = "79998887766",
                    PasswordWatermark          = "Password",
                    EnablePasswordPreview      = true,
                    RememberCheckBoxVisibility = Visibility.Visible,
                    RememberCheckBoxChecked    = config.ShouldRemember,
                };

                var loginDialog = new LoginWithUrlDialog(view, settings)
                {
                    Title = "Login"
                };
                await view.ShowMetroDialogAsync(loginDialog);
                var result = await loginDialog.WaitForButtonPressAsync();
                await view.HideMetroDialogAsync(loginDialog);
                return(result);
            },
                authentication: async(x) =>
            {
                if (x == null)
                {
                    return(false);
                }

                try
                {
                    config.HostUrl        = x.Url;
                    config.ShouldRemember = x.ShouldRemember;
                    _appConfigStorage.Save(config);

                    _domain0Context.HostUrl        = x.Url;
                    _domain0Context.ShouldRemember = x.ShouldRemember;

                    var loginTask = GetLoginTask(x);

                    var userProfile = await _shell.ShowProgress("Login", "Trying to login...")
                                      .WaitOnly(loginTask);

                    var login = x.LoginMode == LoginMode.Email
                            ? userProfile.Email
                            : userProfile.Phone;
                    _shell.Container.Resolve <IDockWindow>().Title =
                        $"Domain0.Desktop - {userProfile.Name} - {login}";

                    return(true);
                }
                catch (AuthenticationContextException e)
                {
                    await _shell.HandleException(e.InnerException, "Login failed", false);
                    return(false);
                }
            },
                authenticationSuccess: () => onSuccess?.Invoke(),
                authenticationFail: () => Application.Current.MainWindow?.Close()
                );
        }
Exemplo n.º 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var shell = UiStarter.Start <IDockWindow>(
                new Bootstrap(),
                new UiShowStartWindowOptions
            {
                Title         = "Kanban.Desktop",
                ToolPaneWidth = 100
            });

            AuthProcess.Start(
                getAuthenticationData: () => LoginDialog.GetAutenticationDataTask(),
                authentication: async(x) =>
            {
                if (x == null)
                {
                    return(false);
                }

                var authContext = shell.Container.Resolve <IAuthenticationContext>();
                return(await authContext.LoginAsync(x.Username, x.Password));
            },
                authenticationSuccess: () =>
            {
                shell.ShowView <ISettingsView>(
                    options: new UiShowOptions
                {
                    Title = "Settings"
                });
                shell.ShowView <IKanbanBoardView>();
                shell.ShowView <IKanbanBoardView>(
                    new KanbanViewRequest
                {
                    ConfigurtaionName = "h_status_v_assigned_c_subject_treker_details"
                },
                    new KanbanShowOptions
                {
                    Title = "Kanban dynamic dimension",
                });
                shell.ShowView <IKanbanBoardView>(
                    new KanbanViewRequest
                {
                    ConfigurtaionName = "ods"
                },
                    new KanbanShowOptions
                {
                    Title = "ods",
                });

                shell.ShowView <IIssueView>(
                    new IssueViewRequest
                {
                    IssueId = 4689
                });

                shell.ShowTool <IIssuesTool>();
            },
                authenticationFail: () => Current.MainWindow.Close());
        }
Exemplo n.º 5
0
        public AuthProcess Do(
            string login,
            string pass,
            string captchaGid  = null,
            string captchaText = null,
            string steamGuard  = null,
            string emailId     = null)
        {
            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(pass))
            {
                throw new ArgumentException("Login or password must not be empty");
            }

            var auth = new AuthProcess();

            var rsa = this.GetRsa(login);

            if (!rsa.Success)
            {
                auth.Message = "Failed to get RSA";
                return(auth);
            }

            var encPass = this.EncryptPassword(pass, rsa.Module, rsa.Exponent);

            if (string.IsNullOrEmpty(encPass))
            {
                throw new SteamException("Failed to get encrypt password");
            }

            var @params = new Dictionary <string, string>
            {
                { "password", encPass },
                { "username", login },
                { "rsatimestamp", rsa.TimeStamp },
                { "remember_login", true.ToString() },
                { "loginfriendlyname", string.Empty },
                { "l", "en" }
            };

            if (!string.IsNullOrEmpty(captchaGid) && !string.IsNullOrEmpty(captchaText))
            {
                @params.Add("captchagid", captchaGid);
                @params.Add("captcha_text", captchaText);
            }
            else
            {
                @params.Add("captchagid", "-1");
                @params.Add("captcha_text", null);
            }

            if (!string.IsNullOrEmpty(steamGuard) && !string.IsNullOrEmpty(emailId))
            {
                @params.Add("emailsteamid", emailId);
                @params.Add("emailauth", steamGuard);
            }
            else if (!string.IsNullOrEmpty(steamGuard))
            {
                @params.Add("twofactorcode", steamGuard);
            }

            var resp  = this._steam.Request(Urls.LoginDo, Method.POST, Urls.Login, @params);
            var jresp = JsonConvert.DeserializeObject <JLogin>(resp.Data.Content);

            auth.Message = jresp.Message;

            if (jresp.Success)
            {
                this.IsAuthorized    = true;
                this.CookieContainer = resp.CookieContainer;
                auth.Success         = true;
                return(auth);
            }

            if (jresp.CaptchaNeeded)
            {
                auth.CaptchaNeeded   = true;
                auth.CaptchaGid      = jresp.CaptchaGid;
                auth.CaptchaImageUrl = MarketUtils.GetCaptchaImageUrl(jresp.CaptchaGid);
            }

            if (jresp.EmailAuthNeeded)
            {
                auth.EmailAuthNeeded = true;
                auth.EmailId         = jresp.EmailId;
            }
            else if (jresp.RequiresTwoFactor)
            {
                auth.TwoFactorNeeded = true;
            }

            return(auth);
        }