Exemplo n.º 1
0
        public static void AuthenticateSmtpGoogleOAuth2(this SmtpClient imap, MailBox account, ILogger log = null)
        {
            if (log == null)
            {
                log = new NullLogger();
            }

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

            if (grantedAccess == null)
            {
                throw new ProtocolException("Access denied");
            }

            log.Info("Smtp SSL connecting to {0}", account.EMail);
            imap.ConnectSsl(account.SmtpServer, account.SmtpPort);

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

            imap.SendEhloHelo();

            log.Info("Smtp logging to {0} via OAuth 2.0", account.EMail);

            imap.Authenticate(account.SmtpAccount, grantedAccess.AccessToken, SaslMechanism.OAuth2);

            log.Info("Smtp logged to {0} via OAuth 2.0", account.EMail);
        }
        private string GetOauthAccessToken(string refreshToken)
        {
            var auth          = new GoogleOAuth2Authorization(Log);
            var grantedAccess = auth.RequestAccessToken(refreshToken);

            if (grantedAccess == null)
            {
                throw new AuthenticationException("XOAUTH2: Access denied.");
            }

            return(grantedAccess.AccessToken);
        }
Exemplo n.º 3
0
        public static void TestGoogleSmtpLoginViaOAuth2(string account, string refresh_token)
        {
            var authorizatior = new GoogleOAuth2Authorization();

            var granted_access = authorizatior.RequestAccessToken(refresh_token);

            if (granted_access == null)
            {
                return;
            }
            var smtp = MailClientBuilder.Smtp();

            smtp.ConnectSsl("smtp.googlemail.com", 465);
            smtp.Authenticate(account, granted_access.AccessToken, SaslMechanism.OAuth2);
            //Do some work...
            smtp.Disconnect();
        }
Exemplo n.º 4
0
        public static void TestGoogleImapLoginViaOAuth2(string account, string refresh_token)
        {
            var authorizatior = new GoogleOAuth2Authorization();

            var granted_access = authorizatior.RequestAccessToken(refresh_token);

            if (granted_access == null)
            {
                return;
            }
            var imap = MailClientBuilder.Imap();

            imap.ConnectSsl("imap.googlemail.com", 993);
            imap.LoginOAuth2(account, granted_access.AccessToken);
            //Do some work...
            imap.Disconnect();
        }
Exemplo n.º 5
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);
        }