summaryrefslogtreecommitdiff
path: root/lisp/erc/erc-services.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/erc/erc-services.el')
-rw-r--r--lisp/erc/erc-services.el58
1 files changed, 28 insertions, 30 deletions
diff --git a/lisp/erc/erc-services.el b/lisp/erc/erc-services.el
index dcd786411f2..fe9cb5b5f17 100644
--- a/lisp/erc/erc-services.el
+++ b/lisp/erc/erc-services.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2002-2004, 2006-2022 Free Software Foundation, Inc.
-;; Maintainer: Amin Bandali <bandali@gnu.org>
+;; Maintainer: Amin Bandali <bandali@gnu.org>, F. Jason Park <jp@neverwas.me>
;; URL: https://www.emacswiki.org/emacs/ErcNickserv
;; This file is part of GNU Emacs.
@@ -174,6 +174,18 @@ function `erc-nickserv-get-password'."
:version "28.1"
:type 'boolean)
+(defcustom erc-auth-source-services-function #'erc-auth-source-search
+ "Function to retrieve NickServ password from auth-source.
+Called with a subset of keyword parameters known to
+`auth-source-search' and relevant to authenticating to nickname
+services. In return, ERC expects a string to send as the
+password, or nil, to fall through to the next method, such as
+prompting. See info node `(erc) Connecting' for details."
+ :package-version '(ERC . "5.4.1") ; FIXME update when publishing to ELPA
+ :type '(choice (const erc-auth-source-search)
+ (const nil)
+ function))
+
(defcustom erc-nickserv-passwords nil
"Passwords used when identifying to NickServ automatically.
`erc-prompt-for-nickserv-password' must be nil for these
@@ -202,7 +214,7 @@ Example of use:
(const QuakeNet)
(const Rizon)
(const SlashNET)
- (symbol :tag "Network name"))
+ (symbol :tag "Network name or session ID"))
(repeat :tag "Nickname and password"
(cons :tag "Identity"
(string :tag "Nick")
@@ -431,34 +443,20 @@ As soon as some source returns a password, the sequence of
lookups stops and this function returns it (or returns nil if it
is empty). Otherwise, no corresponding password was found, and
it returns nil."
- (let (network server port)
- ;; Fill in local vars, switching to the server buffer once only
- (erc-with-server-buffer
- (setq network erc-network
- server erc-session-server
- port erc-session-port))
- (let ((ret
- (or
- (when erc-nickserv-passwords
- (cdr (assoc nick
- (cl-second (assoc network
- erc-nickserv-passwords)))))
- (when erc-use-auth-source-for-nickserv-password
- (let ((secret (cl-first (auth-source-search
- :max 1 :require '(:secret)
- :host server
- ;; Ensure a string for :port
- :port (format "%s" port)
- :user nick))))
- (when secret
- (let ((passwd (plist-get secret :secret)))
- (if (functionp passwd) (funcall passwd) passwd)))))
- (when erc-prompt-for-nickserv-password
- (read-passwd
- (format "NickServ password for %s on %s (RET to cancel): "
- nick network))))))
- (when (and ret (not (string= ret "")))
- ret))))
+ (when-let*
+ ((nid (erc-networks--id-symbol erc-networks--id))
+ (ret (or (when erc-nickserv-passwords
+ (assoc-default nick
+ (cadr (assq nid erc-nickserv-passwords))))
+ (when (and erc-use-auth-source-for-nickserv-password
+ erc-auth-source-services-function)
+ (funcall erc-auth-source-services-function :user nick))
+ (when erc-prompt-for-nickserv-password
+ (read-passwd
+ (format "NickServ password for %s on %s (RET to cancel): "
+ nick nid)))))
+ ((not (string-empty-p ret))))
+ ret))
(defvar erc-auto-discard-away)