1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 04:10:54 -08:00

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.
This commit is contained in:
Roland Winkler 2021-08-05 12:33:21 +02:00 committed by Lars Ingebrigtsen
parent 50d3178a4f
commit 1505dca91f
5 changed files with 30 additions and 6 deletions

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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)))

View file

@ -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