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

OAuth token stored on gitconfig file #1259

Open
mhalano opened this issue Sep 9, 2016 · 10 comments
Open

OAuth token stored on gitconfig file #1259

mhalano opened this issue Sep 9, 2016 · 10 comments

Comments

@mhalano
Copy link

mhalano commented Sep 9, 2016

How can I do to store the OAuth token inside ~/.gitconfig instead ~/.config/hub? I want to do the "!" trick to get the token from my keychain.

@mislav
Copy link
Owner

mislav commented Sep 9, 2016

Hello, right now this isn't possible. However, if you don't wish to have the token stored in ~/.config/hub, you can erase it from there, and have your shell rc file populate the GITHUB_TOKEN environment variable by pulling it dynamically from keychain. Hub will then use the token from environment variable and should not prompt for username/password nor store authentication info in ~/.config/hub.

@mhalano
Copy link
Author

mhalano commented Sep 9, 2016

@mislav Did you think is could be useful put, optionally, token on gitconfig file?

@mislav
Copy link
Owner

mislav commented Sep 9, 2016 via email

@mhalano
Copy link
Author

mhalano commented Sep 10, 2016

Have you a specific reason for that? Tools like going store tokens on
gitconfig.

On Fri, Sep 9, 2016, 19:53 Mislav Marohnić notifications@github.com wrote:

It's possible, but I don't want to use the gitconfig file for anything
related to hub.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#1259 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFvvR4N464ARfkHohVaLjl5NILgx5YIsks5qoeNNgaJpZM4J5L4I
.

Marcos H. Alano

Sent from my Android

@mislav
Copy link
Owner

mislav commented Sep 10, 2016

Have you a specific reason for that?

Yes: to allow people to check their gitconfig in version control in case they back up their dotfiles. Lots of people publish their dotfiles on GitHub, and avoiding storing tokens in there reduces the risk of accidentally publishing your GitHub token.

@mhalano
Copy link
Author

mhalano commented Sep 15, 2016

Interesting. I always saw as standard to put the token inside gitconfig. Lots of tools do that (the tools which support tokens, of course), so I think keep this option available (but not standard) should be good.

@lox
Copy link

lox commented Sep 27, 2016

If users have multiple accounts for work/non-work, what's the best way to have per-project tokens for hub?

@mislav
Copy link
Owner

mislav commented Sep 27, 2016

@lox If you have multiple GitHub accounts, there is no elegant way. You could create a wrapper script for hub:

#!/bin/bash
set -e

# Check $PWD and set the token for this project accordingly:
export GITHUB_TOKEN="..."

exec hub "$@"

Then you can alias hub=my-hub-wrapper and have hub <command> ... invocations dynamically swap out the token based on criteria that you program into the script.

@jasonkarns
Copy link

The example shown above would work really well to leverage git 2.13's conditional includes:
https://git-scm.com/docs/git-config#_conditional_includes

You could configure git to include additional config settings based on the path of the repo. Then the hub wrapper would merely need to invoke git config hub.user

@rndusr
Copy link

rndusr commented May 28, 2020

I would like to argue in favor of reading the token from the repo's .gitconfig.

It is the easiest way to configure different accounts per repo.

You could slap a huge warning in the documenation to not do this and explain why. Anyone who does it anyway should be considered an adult who understands the consequences.

I don't see a reason to publish .gitconfig and anyone who wants to publish their dotfiles will have to sanitize them anyway. Hub protects me from something I'll never do at the cost of making it only usable if I write a wrapper for it.

Any chance you might reconsider?

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

No branches or pull requests

5 participants