private void btnLogin_Click(object sender, EventArgs e) { FacebookSettings fbSettings = new FacebookSettings { ApplicationKey = txtApiKey.Text }; FacebookLoginForm fbLoginDlg = new FacebookLoginForm(fbSettings); FacebookAuthenticationResult fbAuthResult; if (fbLoginDlg.ShowDialog() == DialogResult.OK) { MessageBox.Show("You are logged in."); fbAuthResult = fbLoginDlg.FacebookAuthenticationResult; txtAccessToken.Text = fbAuthResult.AccessToken; txtExpiresIn.Text = fbAuthResult.ExpiresIn.ToString(); btnGetMyInfo.Enabled = true; } else { MessageBox.Show("You must login inorder to access Facebook features."); if (fbLoginDlg.FacebookAuthenticationResult != null) { // it can be null if the user just cancelled. fbAuthResult = fbLoginDlg.FacebookAuthenticationResult; MessageBox.Show(fbAuthResult.ErrorReasonText); } } }
private void loginButton_Click(object sender, EventArgs e) { var loginPopup = new FacebookLoginForm(Constants.LoginUrl); loginPopup.Authorized += async(_, args) => { loginPopup.Close(); var client = new TwainCloudClient(Constants.ApiRoot, args.Tokens); _applicationManager = new ApplicationManager(client); await LoadScanners(); }; loginPopup.ShowDialog(); }
/// <summary> /// Take us through the signin process... /// </summary> /// <param name="a_szApiRoot">our cloud url</param> /// <param name="a_szSigninUrl">our signin url</param> /// <returns></returns> public TwainLocalScannerClient Signin(string a_szApiRoot, string a_szSigninUrl) { // Cleanup... m_twaincloudclient = null; m_twaincloudtokens = null; if (m_twainlocalscannerclient != null) { m_twainlocalscannerclient.Dispose(); m_twainlocalscannerclient = null; } // Remember stuff... m_szApiRoot = a_szApiRoot; m_szSigninUrl = a_szSigninUrl; // Signin... AutoResetEvent autoresetevent = new AutoResetEvent(false); Invoke(new MethodInvoker(delegate { FacebookLoginForm facebookloginform = new FacebookLoginForm(m_szSigninUrl); facebookloginform.Authorized += async(_, args) => { // Form goes bye-bye... facebookloginform.Close(); // Squirrel this away... m_twaincloudtokens = args.Tokens; // Put the authorization bearer token where we can get it... m_twainlocalscannerclient = new TwainLocalScannerClient(EventCallback, this, false); m_twaincloudclient = new TwainCloudClient(m_szApiRoot, m_twaincloudtokens); await m_twainlocalscannerclient.ConnectToCloud(m_twaincloudclient); m_twainlocalscannerclient.m_dictionaryExtraHeaders.Add("Authorization", m_twaincloudtokens.AuthorizationToken); autoresetevent.Set(); }; })); autoresetevent.WaitOne(); // All done... return(m_twainlocalscannerclient); }