Пример #1
0
        private void picOutlook_Click(object sender, EventArgs e)
        {
            _authMode = AuthMode.Outlook;

            wbrMain.Show();
            pnlLogin.Hide();
            btnDefaultAuth.Show();
            picGMailLogin.Hide();
            picOutlook.Hide();
            picYahoo.Hide();
            wbrMain.Navigate(OutlookOAuth2Provider.BuildAuthenticationUri());
        }
Пример #2
0
        private void Authenticate(object arg)
        {
            try
            {
                if (_authMode == AuthMode.Google)
                {
                    GoogleAccessToken token   = GoogleOAuth2Provider.GetAccessToken(_oAuth2Code);
                    GoogleProfile     profile = GoogleOAuth2Provider.GetUserProfile(token);

                    Program.ImapClient.Credentials = new OAuth2Credentials(profile.email, token.access_token);
                }
                else if (_authMode == AuthMode.Outlook)
                {
                    var token   = OutlookOAuth2Provider.GetAccessToken(_oAuth2Code);
                    var profile = OutlookOAuth2Provider.GetUserProfile(token.access_token);
                    Program.ImapClient.Credentials = new OAuth2Credentials(profile.emails.account, token.access_token);
                }
                else if (_authMode == AuthMode.Yahoo)
                {
                    var token = YahooOAuth2Provider.GetAccessToken(_oAuth2Code);
                    Program.ImapClient.Credentials = new OAuth2Credentials(token.xoauth_yahoo_guid, token.access_token, "ImapX");
                }

                if (Program.ImapClient.Login())
                {
                    Invoke(new SuccessDelegate(OnAuthenticateSuccessful));
                }
                else
                {
                    Invoke(new FailedDelegate(OnAuthenticateFailed));
                }
            }
            catch (Exception ex)
            {
                Invoke(new FailedDelegate(OnAuthenticateFailed), new[] { ex });
            }
        }