Skip to content

Instantly share code, notes, and snippets.

@letoh
Last active May 30, 2023 07:32
Show Gist options
  • Select an option

  • Save letoh/5497116 to your computer and use it in GitHub Desktop.

Select an option

Save letoh/5497116 to your computer and use it in GitHub Desktop.
Examples for using auth-source api in Emacs
(let ((auth-source-creation-prompts
'((secret . "password for %u: ")))
(info ...))
...)
(defun get-auth-info (host user &optional port)
(let ((info (nth 0 (auth-source-search
:host host
:user user
:port port
:require '(:user :secret)
:create t))))
(if info
(let ((secret (plist-get info :secret)))
(if (functionp secret)
(funcall secret)
secret))
nil)))
(let ((save-info (plist-get info :save-function)))
(when save-info
(funcall save-info)))
(setq auth-sources (list "~/.secret/authinfo.gpg"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment