public class

OAuth2Authenticator

extends Object
java.lang.Object
   ↳ com.google.code.oauth.OAuth2Authenticator

Class Overview

Performs OAuth2 authentication.

Before using this class, you must call initialize to install the OAuth2 SASL provider.

Summary

Public Constructors
OAuth2Authenticator()
Public Methods
static IMAPStore connectToImap(String userEmail, String oauthToken)
Connects and authenticates to an IMAP server with OAuth2.
static SMTPTransport connectToSmtp(String host, int port, String userEmail, String oauthToken, boolean debug)
Connects and authenticates to an SMTP server with OAuth2.
static void initialize()
Installs the OAuth2 SASL provider.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public OAuth2Authenticator ()

Public Methods

public static IMAPStore connectToImap (String userEmail, String oauthToken)

Connects and authenticates to an IMAP server with OAuth2. You must have called initialize.

Parameters
userEmail Email address of the user to authenticate, for example oauth@gmail.com.
oauthToken The user's OAuth token.
Returns
  • An authenticated IMAPStore that can be used for IMAP operations.

public static SMTPTransport connectToSmtp (String host, int port, String userEmail, String oauthToken, boolean debug)

Connects and authenticates to an SMTP server with OAuth2. You must have called initialize.

Parameters
host Hostname of the smtp server, for example smtp.googlemail.com.
port Port of the smtp server, for example 587.
userEmail Email address of the user to authenticate, for example oauth@gmail.com.
oauthToken The user's OAuth token.
debug Whether to enable debug logging on the connection.
Returns
  • An authenticated SMTPTransport that can be used for SMTP operations.
Throws
Exception

public static void initialize ()

Installs the OAuth2 SASL provider. This must be called exactly once before calling other methods on this class.