Last active
May 30, 2023 07:32
-
-
Save letoh/5497116 to your computer and use it in GitHub Desktop.
Examples for using auth-source api in Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (let ((auth-source-creation-prompts | |
| '((secret . "password for %u: "))) | |
| (info ...)) | |
| ...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (let ((save-info (plist-get info :save-function))) | |
| (when save-info | |
| (funcall save-info))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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