Kungsgeten / hypothesis

Import data from hypothes.is into Emacs
MIT License
55 stars 14 forks source link

Read user and password from authinfo.gpg #2

Open nightscape opened 4 years ago

nightscape commented 4 years ago

Hi @Kungsgeten,

is it possible to read the credentials from the .authinfo.gpg. I'm an Elisp noob, therefore I can't tell from the code...

Thanks for creating this! Looking forward to integrating it into my Building A Second Brain workflow 😄

Kungsgeten commented 4 years ago

Hi! There's nothing built into the package that makes this possible. I haven't used .authinfo much myself, since I use the same Emacs configuration on both Windows and Linux. Maybe this site can help: https://www.masteringemacs.org/article/keeping-secrets-in-emacs-gnupg-auth-sources

nightscape commented 4 years ago

Ok, figured it out with the help of https://emacs.stackexchange.com/a/8072/11825 This can be done by putting the following line into ~/.authinfo.gpg

machine hypothes.is login your_hypothesis_user secret "your_hypothesis_token"

and the following code in your Emacs config

(with-eval-after-load 'random-mode
  (require 'auth-source)
  (let ((auth (nth 0 (auth-source-search :host "hypothes.is"
                                         :requires '(user secret)))))
    (setq hypothesis-token (funcall (plist-get auth :secret))
          hypothesis-username (plist-get auth :user))))

or in Doom Emacs in ~/.doom.d/config.el

(after! hypothesis
  (require 'auth-source)
  (let ((auth (nth 0 (auth-source-search :host "hypothes.is"
                                         :requires '(user secret)))))
    (setq hypothesis-token (funcall (plist-get auth :secret))
          hypothesis-username (plist-get auth :user))))

Should this be put in the README?

Kungsgeten commented 4 years ago

I personally don't feel like it should be in the README since storing personal information seems like a general concept, rather than something specific to this package. Also it feels a bit strange to recommend something regarding safety when I don't understand it myself.

nightscape commented 4 years ago

Some Emacs packages seem to come with auth-source integration by default, e.g. org-jira and Magit, that's why I got to ask in the first place. But I don't mind either way, as it works for me now and my password is safely encrypted in my .authinfo.gpg 😃