emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1505dca: Add support for the oauth2.el library in nnimap and smtp


From: Lars Ingebrigtsen
Subject: master 1505dca: Add support for the oauth2.el library in nnimap and smtpmail
Date: Thu, 5 Aug 2021 06:33:29 -0400 (EDT)

branch: master
commit 1505dca91f2ef8de3ea20fb2177539700ac1f2fc
Author: Roland Winkler <winkler@gnu.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add support for the oauth2.el library in nnimap and smtpmail
    
    * doc/misc/gnus.texi (Customizing the IMAP Connection):
    * doc/misc/smtpmail.texi (Authentication): Mention it.
    
    * lisp/gnus/nnimap.el (nnimap-login): Support oauth2.
    
    * lisp/mail/smtpmail.el (smtpmail-try-auth-method): New function
    for oauth2.
---
 doc/misc/gnus.texi     |  3 ++-
 doc/misc/smtpmail.texi | 12 +++++++-----
 etc/NEWS               |  6 ++++++
 lisp/gnus/nnimap.el    |  7 +++++++
 lisp/mail/smtpmail.el  |  8 ++++++++
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index c8d5a86..015a170 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -14516,7 +14516,8 @@ this should be set to @code{anonymous}.  If this 
variable isn't set,
 the normal login methods will be used.  If you wish to specify a
 specific login method to be used, you can set this variable to either
 @code{login} (the traditional @acronym{IMAP} login method),
-@code{plain} or @code{cram-md5}.
+@code{plain}, @code{cram-md5} or @code{xoath2}.  (The latter method
+requires using the @file{oauth2.el} library.)
 
 @item nnimap-expunge
 When to expunge deleted messages.  If @code{never}, deleted articles
diff --git a/doc/misc/smtpmail.texi b/doc/misc/smtpmail.texi
index ca7dabe..f5d5675 100644
--- a/doc/misc/smtpmail.texi
+++ b/doc/misc/smtpmail.texi
@@ -264,12 +264,14 @@ file, @pxref{Top,,auth-source, auth, Emacs auth-source 
Library}.
 @cindex CRAM-MD5
 @cindex PLAIN
 @cindex LOGIN
-The process by which the SMTP library authenticates you to the server
-is known as ``Simple Authentication and Security Layer'' (SASL).
-There are various SASL mechanisms, and this library supports three of
-them: CRAM-MD5, PLAIN, and LOGIN, where the first uses a form of
+The process by which the @acronym{SMTP} library authenticates you to
+the server is known as ``Simple Authentication and Security Layer''
+(@acronym{SASL}).  There are various @acronym{SASL} mechanisms, and
+this library supports three of them: @code{cram-md5}, @code{plain},
+@code{login} and @code{xoauth2}, where the first uses a form of
 encryption to obscure your password, while the other two do not.  It
-tries each of them, in that order, until one succeeds.  You can
+tries each of them, in that order, until one succeeds.
+(@code{xoauth2} requires using the @file{oauth2.el} library.  You can
 override this by assigning a specific authentication mechanism to a
 server by including a key @code{smtp-auth} with the value of your
 preferred mechanism in the appropriate @file{~/.authinfo} entry.
diff --git a/etc/NEWS b/etc/NEWS
index f0fa686..bfbae9f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1000,6 +1000,9 @@ String or list of strings specifying switches for Git log 
under VC.
 ** Gnus
 
 +++
+*** nnimap now supports the oath2.el library.
+
++++
 *** New Summary buffer sort options for extra headers.
 The extra header sort option ('C-c C-s C-x') prompts for a header
 and fails if no sort function has been defined.  Sorting by
@@ -1188,6 +1191,9 @@ take the actual screenshot, and defaults to "ImageMagick 
import".
 ** Smtpmail
 
 +++
+*** smtpmail now supports using the oauth2.el library.
+
++++
 *** New user option 'smtpmail-store-queue-variables'.
 If non-nil, SMTP variables will be stored together with the queued
 messages, and will then be used when sending with
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 3e2a202..3cf6545 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -599,6 +599,13 @@ during splitting, which may be slow."
              (eq nnimap-authenticator 'anonymous)
             (eq nnimap-authenticator 'login)))
     (nnimap-command "LOGIN %S %S" user password))
+   ((and (nnimap-capability "AUTH=XOAUTH2")
+         (eq nnimap-authenticator 'xoauth2))
+    (nnimap-command  "AUTHENTICATE XOAUTH2 %s"
+                     (base64-encode-string
+                      (format "user=%s\001auth=Bearer %s\001\001"
+                              (nnimap-quote-specials user)
+                              (nnimap-quote-specials password)))))
    ((and (nnimap-capability "AUTH=CRAM-MD5")
         (or (null nnimap-authenticator)
             (eq nnimap-authenticator 'cram-md5)))
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 33bdd05..8e3927c 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -636,6 +636,14 @@ USER and PASSWORD should be non-nil."
           (base64-encode-string (concat "\0" user "\0" password) t))
    235))
 
+(cl-defmethod smtpmail-try-auth-method
+  (process (_mech (eql xoauth2)) user password)
+  (smtpmail-command-or-throw
+   process
+   (concat "AUTH XOAUTH2 "
+           (base64-encode-string
+            (concat "user=" user "\1auth=Bearer " password "\1\1") t))))
+
 (defun smtpmail-response-code (string)
   (when string
     (with-temp-buffer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]