Exemple #1
0
        void _doOauth()
        {
            // AccessToken is existed, if it is not expired, use it directly, otherwise refresh it.
            if (!string.IsNullOrEmpty(_oauthWrapper.OauthProvider.AccessToken))
            {
                if (!_oauthWrapper.IsAccessTokenExpired)
                {
                    return;
                }

                StatusBarSend.Text = "Refreshing access token ...";
                try
                {
                    _oauthWrapper.RefreshAccessToken();
                }
                catch
                {
                    StatusBarSend.Text = "Failed to refresh access token, try to get a new access token ...";
                }
            }

            using (FormOauth DialogOauth = new FormOauth())
            {
                DialogOauth.OauthWrapper = _oauthWrapper;
                DialogOauth.ShowDialog();
            }

            StatusBarSend.Text = "Requesting access token ...";
            _oauthWrapper.RequestAccessTokenAndUserEmail();
            StatusBarSend.Text = "Oauth is completed, ready to send email.";
        }
Exemple #2
0
        private bool _tryOauth()
        {
            if (ComboBoxAuthType.SelectedIndex != (int)ServerAuthType.AuthXOAUTH2)
            {
                // We don't need to login user by Gmail XOAUTH
                return(true);
            }

            // AccessToken is existed, if it is not expired, use it directly, otherwise refresh it.
            if (!string.IsNullOrEmpty(_oauthWrapper.OauthProvider.AccessToken))
            {
                if (!_oauthWrapper.IsAccessTokenExpired)
                {
                    return(true);
                }

                textStatus.Text = "Refreshing access token ...";
                try
                {
                    _oauthWrapper.RefreshAccessToken();
                }
                catch
                {
                    textStatus.Text = "Failed to refresh access token, try to get a new access token ...";
                }
            }

            using (FormOauth DialogOauth = new FormOauth())
            {
                DialogOauth.OauthWrapper = _oauthWrapper;
                DialogOauth.ShowDialog();
            }

            try
            {
                textStatus.Text = "Requesting access token ...";
                _oauthWrapper.RequestAccessTokenAndUserEmail();
                textStatus.Text = "Oauth is completed.";
                return(true);
            }
            catch (Exception ep)
            {
                MessageBox.Show(ep.Message);
                textStatus.Text = ep.Message;
                return(false);
            }
        }