From: Roland Winkler Date: Thu, 5 Aug 2021 10:33:21 +0000 (+0200) Subject: Add support for the oauth2.el library in nnimap and smtpmail X-Git-Tag: emacs-28.0.90~1591^2~28 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1505dca91f2ef8de3ea20fb2177539700ac1f2fc;p=emacs.git 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. --- diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi index c8d5a868ed2..015a170e5e1 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 ca7dabe6545..f5d567533b6 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 f0fa686bc9c..bfbae9fc5da 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -999,6 +999,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 @@ -1187,6 +1190,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 diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el index 3e2a202a6cf..3cf65453f3b 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 33bdd050bdc..8e3927cdcf2 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