Commit graph

24 commits

Author SHA1 Message Date
Jonathan Mayer
1eefda0b45
gh auth login: add git protocol flag (#5158)
Co-authored-by: Mislav Marohnić <mislav@github.com>
2022-02-17 19:35:59 +00:00
Mislav Marohnić
a3f0940c62
Merge pull request #5032 from cli/ask-stubber
Improve Survey stubber for tests
2022-01-17 12:32:28 +01:00
Mislav Marohnić
583af3e54c
Allow gh auth git-credential to authenticate GitHub Gist requests (#3064)
* Allow `gh auth git-credential` to authenticate GitHub Gist requests

When there are stored credentials for `example.com`, allow using them to
authenticate requests to `gist.example.com` as well.

* Fix writing out of credential config

* remove unneccessary function

* actually delete

Co-authored-by: nate smith <vilmibm@github.com>
2022-01-14 22:18:07 +00:00
Mislav Marohnić
e43cb2b880 Port more legacy stubs to the new ask stubber 2022-01-14 19:34:15 +01:00
Mislav Marohnić
be9f01101a Tweak auth flow re: interactivity
Fixes non-interactive login flow and make sure "prompt" configuration is
respected by never prompting if it was explicitly disabled.

No longer asks to press Enter again after "Authentication complete"
message, since that didn't provide any value to the user.
2022-01-12 15:50:51 +01:00
Nick Cooper
a408f24d3a auth: add noninteractive flow to login/refresh 2022-01-11 22:44:46 +01:00
Des Preston
94a640bd2a
Add auth setup-git for setting up gh as a git credential helper (#4246)
Adds a new command `gh auth setup-git [<hostname>]` that sets up git to
use the GitHub CLI as a credential helper.

The gist is that it runs these two git commands for each hostname the
user is authenticated with.

```
git config --global --replace-all 'credential.https://github.com.helper' ''
git config --global --add 'credential.https://github.com.helper' '!gh auth git-credential'
```

If a hostname flag is given, it'll setup GH CLI as a credential helper
for only that hostname.

If the user is not authenticated with any git hostnames, or the user is
not authenticated with the hostname given as a flag, it'll print an
error.

Co-authored-by: Mislav Marohnić <mislav@github.com>
2021-12-02 16:38:34 +00:00
Mislav Marohnić
2c86e671f3 Enable gh auth login for github.localhost 2021-10-18 20:01:18 +02:00
Mislav Marohnić
89ad870190 auth refresh: preserve existing scopes when requesting new ones
When there was a previously valid token that was granted some scopes,
ensure all those scopes will be re-requested when doing the
authentication flow for the new token.
2021-10-14 19:52:59 +02:00
Mislav Marohnić
11fbb60ae7 Rename the module to "github.com/cli/cli/v2" 2021-08-25 12:41:30 +02:00
Mislav Marohnić
21521b06b9 Check git presence during auth login only if it's going to be needed 2021-08-11 19:22:16 +02:00
Mislav Marohnić
98f1f5ec0d Use absolute path when configuring gh as git credential
This keeps git operations working even when PATH is modified, e.g. `brew
update` will work even though Homebrew runs the command explicitly
without `/usr/local/bin` in PATH.

Additionally, this inserts a blank value for `credential.*.helper` to
instruct git to ignore previously configured credential helpers, i.e.
those that might have been set up in system configuration files. We do
this because otherwise, git will store the credential obtained from gh
in every other credential helper in the chain, which we want to avoid.

Before:

    git config --global credential.https://github.com.helper '!gh auth git-credential'

After:

    git config --global credential.https://github.com.helper ''
    git config --global --add credential.https://github.com.helper '!/path/to/gh auth git-credential'
2021-03-03 16:20:21 +01:00
Mislav Marohnić
cfddda8829 Indicate workflow scope is GHE 3.0+ only during auth login 2021-02-23 10:52:29 +01:00
Mislav Marohnić
f807795491 Fix pasting Personal Access Token to auth login for GHE 2021-02-23 10:19:11 +01:00
Mislav Marohnić
1a9e42ed55 Add ssh-key add command and publish ssh-key 2021-02-17 19:46:59 +01:00
Mislav Marohnić
4a49e3526c Merge remote-tracking branch 'origin' into writeorg-oauth-scope 2021-02-17 17:11:24 +01:00
Mislav Marohnić
b4bf8cda8d Close pubkey file after reading 2021-02-17 17:01:14 +01:00
Mislav Marohnić
87fcda5fbc Add tests for SSH login flow 2021-02-17 16:52:40 +01:00
Mislav Marohnić
9550ad0159
Tweak prompt for SSH passphrase
Co-authored-by: Amanda Pinsker <ampinsk@github.com>
2021-02-05 10:16:42 +01:00
Mislav Marohnić
1bd6d7b36c Extract parts of HTTPS-related setup shared between login and refresh 2021-02-04 18:36:42 +01:00
Mislav Marohnić
5a110c8e42 Add SSH key generation & uploading to gh auth login flow 2021-02-01 23:34:00 +01:00
Mislav Marohnić
c9407b2629 More descriptive error when aborting auth due to environment variables
Old message:

    read-only token in GH_TOKEN cannot be modified

This message was vague and some users did not understand that this
refers to the value that is read from environment variables.

New message:

    $ GH_TOKEN=123 ghd auth login -h github.com
    The value of the GH_TOKEN environment variable is being used for authentication.
    To have GitHub CLI store credentials instead, first clear the value from the environment.
2021-01-20 18:27:35 +01:00
Mislav Marohnić
381e83e6e5 Extend git credential prompt to auth refresh 2020-12-07 20:01:16 +01:00
Mislav Marohnić
c39dc28fa1 Rename auth/client to auth/shared 2020-12-07 17:08:42 +01:00