You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry; I forgot to reply to your issue when I viewed this last.
As confusing as the authentication situation is now, this is actually expected behavior right now. With git and hub, you're authenticating in two different ways: one is for the git protocol used for cloning/pushing (protocols supported: git:, ssh:, https:) and the other is for hub's API access (protocols supported: https:).
I want to make this more user friendly, of course. Such as, if you have the password cached in credential helper like you described, we can try reusing it. The only problem is that the "password" you use in git credential cache might not be a real password, but a personal access token with clone privileges. Such token is necessary for accounts that use 2-factor authentication. This token is useless for hub because it doesn't have sufficient privileges to do all needed API operations.
Can you explain in a little more detail what you mean here? Are you talking specifically about "what if this happens and it causes an error, and the user doesn't know that he needs to replace his existing limited token with one that has full access"? Or do you mean that having a limited token live side-by-side with a full hub-capable token is a legitimate use case that we need to support?
When you make a request to the GitHub API, it returns a header X-OAuth-Scopes, the value of which is the list of the scopes that have been applied to the token, separated by a comma and a space. If one of the scopes is repo, the token has all the permissions we need. Otherwise, we'll need to generate a new token. As for how to store that token alongside an existing one, we could store it with a custom path:
Git by default filters out paths if the protocol is HTTP(S), so we have to force credential.useHttpPath to true on the commands to ensure that we don't override any existing tokens. We use a path that's invalid as an actual repository on GitHub to avoid overriding any tokens if there a particular repo sets credential.useHttpPath to true or the user has it set that way system-wide. Here's what happens under those conditions:
As a side note, this is one instance where GitHub's somewhat-anemic permissions model for Personal Access Tokens helps us, as the only way to give a token access to private repositories is to give it full repo access. As such, most people that are using a personal access token for GitHub access will probably have given it repo access, allowing us to reuse it.
I ended up here while trying to determine if hub supported loading credentials from a ~/.netrc file.
One way to distinguish a limited token used only for cloning from a token used for API access could be through the hostname, assuming the cloning-only token would be using github.com, while a token for API access could be more specifically tied to api.github.com.
This would still leave the problem open for Github Enterprise installations, where API is behind an /api/v3 path, and not usually a separate api.* domain.
I made a reeeeeally rough version of this that works in the positive case when a GitHub personal token has already been saved in the git credential helper (I use osxkeychain):
I store my personal access token as my password for github.com in git credentials. But I love the idea of using api.github.com. That's a little tricky to interoperate with GitHub enterprise and api subdomains versus api paths.
Activity
[-]hub doesn[/-][+]hub doesn't recognize credentials in cache[/+]mislav commentedon Sep 13, 2016
Sorry; I forgot to reply to your issue when I viewed this last.
As confusing as the authentication situation is now, this is actually expected behavior right now. With git and hub, you're authenticating in two different ways: one is for the git protocol used for cloning/pushing (protocols supported:
git:,ssh:,https:) and the other is for hub's API access (protocols supported:https:).I want to make this more user friendly, of course. Such as, if you have the password cached in credential helper like you described, we can try reusing it. The only problem is that the "password" you use in git credential cache might not be a real password, but a personal access token with
cloneprivileges. Such token is necessary for accounts that use 2-factor authentication. This token is useless for hub because it doesn't have sufficient privileges to do all needed API operations.mislav commentedon Dec 24, 2016
Cross-linking these notes here as a TODO item: how to implement the credential helper protocol #630 (comment)
/cc @elyscape @technomancy so you follow this thread instead of the other one, which is closed
technomancy commentedon Dec 28, 2016
Can you explain in a little more detail what you mean here? Are you talking specifically about "what if this happens and it causes an error, and the user doesn't know that he needs to replace his existing limited token with one that has full access"? Or do you mean that having a limited token live side-by-side with a full
hub-capable token is a legitimate use case that we need to support?elyscape commentedon Dec 28, 2016
One way to deal with this would be to check for an existing token and, if one is present, check the permissions on it. Example:
When you make a request to the GitHub API, it returns a header
X-OAuth-Scopes, the value of which is the list of the scopes that have been applied to the token, separated by a comma and a space. If one of the scopes isrepo, the token has all the permissions we need. Otherwise, we'll need to generate a new token. As for how to store that token alongside an existing one, we could store it with a custom path:Git by default filters out paths if the protocol is HTTP(S), so we have to force
credential.useHttpPathtotrueon the commands to ensure that we don't override any existing tokens. We use a path that's invalid as an actual repository on GitHub to avoid overriding any tokens if there a particular repo setscredential.useHttpPathtotrueor the user has it set that way system-wide. Here's what happens under those conditions:elyscape commentedon Dec 28, 2016
As a side note, this is one instance where GitHub's somewhat-anemic permissions model for Personal Access Tokens helps us, as the only way to give a token access to private repositories is to give it full
repoaccess. As such, most people that are using a personal access token for GitHub access will probably have given itrepoaccess, allowing us to reuse it.biochimia commentedon May 16, 2017
I ended up here while trying to determine if
hubsupported loading credentials from a~/.netrcfile.One way to distinguish a limited token used only for cloning from a token used for API access could be through the hostname, assuming the cloning-only token would be using
github.com, while a token for API access could be more specifically tied toapi.github.com.This would still leave the problem open for Github Enterprise installations, where API is behind an
/api/v3path, and not usually a separateapi.*domain.segevfiner commentedon Feb 14, 2019
Storing the token as plain text isn't all that secure, this should really be supported.
sj26 commentedon Jul 27, 2019
I made a reeeeeally rough version of this that works in the positive case when a GitHub personal token has already been saved in the git credential helper (I use osxkeychain):
master...sj26:git-credentials
I store my personal access token as my password for
github.comin git credentials. But I love the idea of usingapi.github.com. That's a little tricky to interoperate with GitHub enterprise and api subdomains versus api paths.