Exemplo n.º 1
0
 private void buttonLogin_Click(object sender, EventArgs e)
 {
     var authdg = new OAuthLoginAssistant(m_vk, VK.SecurityFlag.Audios);
     authdg.LoginCompleted += authdg_LoginCompleted;
     authdg.LoginFailed += authdg_LoginFailed;
     authdg.CreateForm(VK.OAuthLoginDisplay.mobile, true);
     authdg.WebLoginForm.Size = new Size(500, 350);
     authdg.WebLoginForm.ShowDialog();
 }
Exemplo n.º 2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            // Ensure not authorized already
            if (MyVK.IsAuthorized && !MyVK.Token.HasExpired)
            {
                MessageBox.Show("Already authorized session!");
                return;
            }

            // Initialize OAuth login assistant class for out VKSession instance with options
            OAuthLoginAssistant oAuthLogin = new OAuthLoginAssistant(
                authSession: MyVK,
                securityScope: this.SecurityScope);

            // Intialize login dialog form with WebBrowser for user
            oAuthLogin.CreateForm(
                display: VK.OAuthLoginDisplay.popup,
                revokePermissions: true);

            // LoginCompleted event handler
            oAuthLogin.LoginCompleted += 
                (   (OAuthLoginAssistant _sender) => 
                    MessageBox.Show("Authorization done!", "VK9")   );

            // LoginFailed event handler
            oAuthLogin.LoginFailed +=
                (   (OAuthLoginAssistant _sender, string _error, string _reason, string _description) =>
                    MessageBox.Show(string.Format("Error: {1}{0}Reason: {2}{0}Description: {3}", _error, _reason, _description), "Login failed")    );

            // Show the dialog in modal state
            oAuthLogin.WebLoginForm.ShowDialog();

            // Dispose of resources
            // Timer is needed to fix WebBrowser control bugfix (call just Dispose() without UI delay and see bug in action)
            var bugged = new System.Timers.Timer(500) { AutoReset = false };
            bugged.Elapsed += 
                (object _sender, ElapsedEventArgs _e) =>
                    oAuthLogin.Dispose();
            bugged.Start();
        }