From 36d65c6d8fd689b5c24da224c97bbc1ba9a09dd6 Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 8 Oct 2012 17:03:52 -0400 Subject: [PATCH] Add xoauth2 support --- README.md | 6 ++++-- lib/imap.js | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 813bd98..7045b91 100644 --- a/README.md +++ b/README.md @@ -375,7 +375,9 @@ ImapConnection Functions * **password** - <_string_> - Password for plain-text authentication. - * **xoauth** - <_string_> - OAuth token for [OAuth authentication](https://sites.google.com/site/oauthgoog/Home/oauthimap) for servers that support it. + * **xoauth** - <_string_> - OAuth token for [OAuth authentication](https://sites.google.com/site/oauthgoog/Home/oauthimap) for servers that support it (See Andris Reinman's [xoauth.js](https://github.com/andris9/inbox/blob/master/lib/xoauth.js) module to help generate this string). + + * **xoauth2** - <_string_> - OAuth2 token for [The SASL XOAUTH2 Mechanism](https://developers.google.com/google-apps/gmail/xoauth2_protocol#the_sasl_xoauth2_mechanism) for servers that support it (See Andris Reinman's [xoauth2](https://github.com/andris9/xoauth2) module to help generate this string). * **host** - <_string_> - Hostname or IP address of the IMAP server. **Default:** "localhost" @@ -637,4 +639,4 @@ Several things not yet implemented in no particular order: * UNSELECT (via UNSELECT extension -- http://tools.ietf.org/html/rfc3691) * SORT (via SORT extension -- http://tools.ietf.org/html/rfc5256) * THREAD (via THREAD=ORDEREDSUBJECT and/or THREAD=REFERENCES extension(s) -- http://tools.ietf.org/html/rfc5256) - * ID (via ID extension -- http://tools.ietf.org/html/rfc2971) ? \ No newline at end of file + * ID (via ID extension -- http://tools.ietf.org/html/rfc2971) ? diff --git a/lib/imap.js b/lib/imap.js index f4054ad..b5a71ba 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -1198,6 +1198,9 @@ ImapConnection.prototype._login = function(cb) { if (this._serverSupports('AUTH=XOAUTH') && 'xoauth' in this._options) { this._send('AUTHENTICATE XOAUTH ' + utils.escape(this._options.xoauth), fnReturn); + } else if (this._serverSupports('AUTH=XOAUTH2') && 'xoauth2' in this._options) { + this._send('AUTHENTICATE XOAUTH2 ' + utils.escape(this._options.xoauth2), + fnReturn); } else if (this._options.username !== undefined && this._options.password !== undefined) { this._send('LOGIN "' + utils.escape(this._options.username) + '" "'