Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual token not being detected #57

Closed
juliusdelta opened this issue Apr 11, 2018 · 12 comments
Closed

Manual token not being detected #57

juliusdelta opened this issue Apr 11, 2018 · 12 comments

Comments

@juliusdelta
Copy link

juliusdelta commented Apr 11, 2018

Emacs Version: GNU Emacs 25.3.1 (x86_64-apple-darwin16.5.0, NS appkit-1504.82 Version 10.12.4 (Build 16E195)) of 2017-10-24

~/.authinfo:
machine api.github.com login juliusdelta^magithub password 1111111111111...

Emacs Config:
(setq auth-sources '("~/.authinfo"))

  (use-package magithub
    :after magit
    :ensure t
    :config (magithub-feature-autoinject t))

I do also have magit & evil-magit installed.

Issue: Whenever I run magit-status I get prompted by the setup wizard to auth my Github credentials. I thought this wouldn't be possible cause I have 2FA enabled.

I'm under the impression ghub looks for auth-sources files and pulls info from there before starting the wizard. It doesn't seem to be doing that. My token is also stored as Emacs package magithub @ ... like the wizard says. Unsure what the issue is or how to troubleshoot further.

When I do just follow the wizard, I get json readtable error, but like I said I thought I couldn't use the wizard with 2FA.

juliusdelta added a commit to juliusdelta/dotfiles-archive-2018 that referenced this issue Apr 11, 2018
This adds the auth-sources variable to my config to ensure that the
right file is being pulled with my github token. However it appears that
ghub does not pull from this file as I'm getting the wizard still even
though I'm not supposed to cause I have 2FA turned on. I've opened an
issue magit/ghub#57 so hopefully they'll get back to me.
@dangom
Copy link

dangom commented Apr 12, 2018

Same issue here. I'm on Emacs 26 with the latest ghub

@tarsius
Copy link
Member

tarsius commented Apr 12, 2018

Does the line end with a newline character?
Are there any comments in the file?

@tarsius
Copy link
Member

tarsius commented Apr 12, 2018

Also try (ghub--token "api.github.com" "USERNAME" "magithub" t) directly.

@dangom
Copy link

dangom commented Apr 13, 2018

Wow, interesting observation. I did have comments on the top of the file setting some file-local variables. After removing the line everything works fine. Thank you for the project, and for your prompt response. =)

@tarsius
Copy link
Member

tarsius commented Apr 13, 2018

Could you please try to revert the "fix" and post the file's contents (sans secrets). ghub already patches auth-source so that that sees entries that come before a commented line, but I cannot reproduce the issue when the file begins with a comment.

(advice-add 'auth-source-netrc-parse-next-interesting :around
            'auth-source-netrc-parse-next-interesting@save-match-data)
(defun auth-source-netrc-parse-next-interesting@save-match-data (fn)
  "Save match-data for the benefit of caller `auth-source-netrc-parse-one'.
Without wrapping this function in `save-match-data' the caller
won't see the secret from a line that is followed by a commented
line."
  (save-match-data (funcall fn)))

@tarsius
Copy link
Member

tarsius commented Apr 13, 2018

This works for me:

# -*- epa-file-encrypt-to: ("jonas@bernoul.li") -*-
machine api.github.com login tarsius^foo password s

and with the above kludge this works too

machine api.github.com login tarsius^foo password s
# -*- epa-file-encrypt-to: ("jonas@bernoul.li") -*-

@dangom
Copy link

dangom commented Apr 13, 2018

Same as yours but without the comment mark, i.e.:

-*- epa-file-encrypt-to: ("name@server") -*-
machine api.github.com login name^foo password s

@dangom
Copy link

dangom commented Apr 13, 2018

With the fix reverted, ghub will continue working fine on repositories it already knows, but the problem will show up again when accessing a new repo.

Adding the comment mark # solves the issue.

@tarsius
Copy link
Member

tarsius commented Apr 14, 2018

I have added a warning about this to the manual.

If you store the token in a file like ~~/.authsource~, then note that
auth-source's parsing of that file is brittle. Make sure the file
ends with a newline character, that there are no empty or invalid
lines, and that all comments are prefixed with #.

@juliusdelta I'm hoping that following this advice will do the trick for you too. If not, then let us know.

@tarsius tarsius closed this as completed Apr 14, 2018
@juliusdelta
Copy link
Author

@tarsius thanks for checking into this. Unfortunately it's still not working. I've removed any and all comments and ensured it ended with a newline character, (which I'm assuming just means \n either way I tried it with and without). I also did ran M-x auth-source-forget-all-cached each time I changed something with no luck. I'm not 100% sure how to continue troubleshooting, if you give me some next steps I'm more than happy to do them and try to get you more info.

@tarsius
Copy link
Member

tarsius commented Apr 14, 2018

if you give me some next steps I'm more than happy to do them and try to get you more info.

Try to narrow the issue down.

Try using (ghub--token "api.github.com" "USERNAME" "magithub" t) directly. Depending on whether that works we will have to look closer at the rest of ghub (and what you are doing) or auth-source.

@tarsius tarsius reopened this Apr 14, 2018
@tarsius
Copy link
Member

tarsius commented May 21, 2018

I am going to assume this is a "recompile everything and restart Emacs" issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants