magit/ghub

`auth-source-search` not returning `:secret` in Emacs 25.2.2

Closed this issue · 3 comments

I had a little struggle to debug why I was always getting prompted to create a token when calling ghub-get and friends. I found in the end that the call to auth-source-search in ghub--auth-source-get doesn't return any value for the :secret key when :max 1 is passed. If :max 2 or higher is passed or the argument is not passed then :secret is present. With Emacs 26.1 this works as expected.

My .authinfo file is as follows:

machine api.github.com login rneatherway^ghub password 11111..

I raise this here because I saw you said in #57 that this package patches auth-source. Let me know if I can provide any further information.

The :max was added in response to #24. However that issue mentions that :max should come last, which I seem to have ignored. Please try this patch:

diff --git a/ghub.el b/ghub.el
index 4894e7b..b6b1ef8 100644
--- a/ghub.el
+++ b/ghub.el
@@ -683,8 +683,8 @@ (defun ghub--token (host username package &optional nocreate forge)
                 ;; value, but in our case that is a situation that needs
                 ;; fixing so we want to keep trying by invalidating that
                 ;; information.  The (:max 1) is needed for Emacs releases
-                ;; before 26.1.
-                (auth-source-forget (list :max 1 :host host :user user))
+                ;; before 26.1. #24 #64
+                (auth-source-forget (list :host host :user user :max 1))
                 (and (not nocreate)
                      (if (eq forge 'gitlab)
                          (error
@@ -819,7 +819,8 @@ (defun ghub--read-2fa-code ()
 
 (defun ghub--auth-source-get (keys &rest spec)
   (declare (indent 1))
-  (let ((plist (car (apply #'auth-source-search :max 1 spec))))
+  (let ((plist (car (apply #'auth-source-search
+                           (append spec (list :max 1))))))
     (mapcar (lambda (k)
               (plist-get plist k))
             keys)))

That works perfectly, thanks.

Thanks for all your hard work on magit, I use it everyday at work and it saves me so much time! I supported your Kickstarter and I'd be happy to do so again.

You're weclome and thanks!