Пример #1
0
        private void AuthenticateImapGoogleOAuth2(Imap4Client imap)
        {
            var auth           = new GoogleOAuth2Authorization();
            var granted_access = auth.RequestAccessToken(Account.RefreshToken);

            if (granted_access == null)
            {
                return;
            }
            _log.Info("IMAP SSL connecting to {0}", Account.EMail);
            imap.ConnectSsl(Account.Server, Account.Port);

            _log.Info("IMAP connecting OK {0}", Account.EMail);

            _log.Info("IMAP logging to {0} via OAuth 2.0", Account.EMail);
            imap.LoginOAuth2(Account.Account, granted_access.AccessToken);
            _log.Info("IMAP logged to {0} via OAuth 2.0", Account.EMail);
        }
        private void AuthenticateImapGoogleOAuth2(Imap4Client imap)
        {
            var auth           = new GoogleOAuth2Authorization(_log);
            var granted_access = auth.RequestAccessToken(Account.RefreshToken);

            if (granted_access == null)
            {
                throw new DotNetOpenAuth.Messaging.ProtocolException("Access denied");
            }
            _log.Info("IMAP SSL connecting to {0}", Account.EMail);
            imap.ConnectSsl(Account.Server, Account.Port);

            _log.Info("IMAP connecting OK {0}", Account.EMail);

            _log.Info("IMAP logging to {0} via OAuth 2.0", Account.EMail);
            imap.LoginOAuth2(Account.Account, granted_access.AccessToken);
            _log.Info("IMAP logged to {0} via OAuth 2.0", Account.EMail);
        }
        public static void AuthenticateImapGoogleOAuth2(this Imap4Client imap, MailBox account, ILogger log = null)
        {
            if (log == null)
            {
                log = new NullLogger();
            }

            var auth           = new GoogleOAuth2Authorization(log);
            var granted_access = auth.RequestAccessToken(account.RefreshToken);

            if (granted_access == null)
            {
                throw new DotNetOpenAuth.Messaging.ProtocolException("Access denied");
            }
            log.Info("IMAP SSL connecting to {0}", account.EMail);
            imap.ConnectSsl(account.Server, account.Port);

            log.Info("IMAP connecting OK {0}", account.EMail);

            log.Info("IMAP logging to {0} via OAuth 2.0", account.EMail);
            imap.LoginOAuth2(account.Account, granted_access.AccessToken);
            log.Info("IMAP logged to {0} via OAuth 2.0", account.EMail);
        }