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

use gh CLI to get OAuth token #335

Open
ggoretkin-bdai opened this issue Jun 13, 2023 · 5 comments
Open

use gh CLI to get OAuth token #335

ggoretkin-bdai opened this issue Jun 13, 2023 · 5 comments

Comments

@ggoretkin-bdai
Copy link

There are a few ways that the gh CLI represents a token, including via an environment variable GH_TOKEN

In my development environment

gh auth status --show-token

displays the the token.

However:

$ git-spr --version
> git rev-parse --show-toplevel
4:48PM WRN ../../Users/runner/work/spr/spr/github/githubclient/client.go:89 > failed to read gh cli config file error="failed to open gh cli config file: open /home/ggoretkin/.config/gh/hosts.yml: no such file or directory"
4:48PM WRN ../../Users/runner/work/spr/spr/github/githubclient/client.go:101 > failed to read hub config file error="failed to open hub config file: open /home/ggoretkin/.config/hub: no such file or directory"

No GitHub OAuth token found! You can either create one
at https://github.com/settings/tokens and set the GITHUB_TOKEN environment variable,
or use the official "gh" CLI (https://cli.github.com) config to log in:

	$ gh auth login

Alternatively, configure a token manually in ~/.config/hub:

	github.com:
	- user: <your username>
	  oauth_token: <your token>
	  protocol: https

This configuration file is shared with GitHub's "hub" CLI (https://hub.github.com/),
so if you already use that, spr will automatically pick up your token.
@ggoretkin-bdai
Copy link
Author

Note that as of https://github.com/cli/cli/releases/tag/v2.24.0 , the hosts.yml file is not used anymore.

@eko-wibowo
Copy link

eko-wibowo commented Jul 24, 2023

new user here, I'm confused by this as well, I did gh auth login however git spr status still says no token found

I've tried to configure manually token in ~/.config/hub by adding token from https://github.com/settings/tokens and gh auth status --show-token but both doesn't seem to work. how to configure this ?

update: storing the token in GH_TOKEN works

@piefel
Copy link

piefel commented Dec 11, 2023

I am trying to connect to our Github Enterprise server, and observe the same behaviour: Logged in fine when using gh auth status, but spr does not pick it up. I am unable to set up ~/.config/hub such that it would show any effect – perhaps the message here is not correct?

Setting the token in GITHUB_TOKEN as suggested in the help message works fine. (Not the one mentioned by @eko-wibowo.)

@simenbrekken-visma
Copy link
Contributor

TL;DR: gh auth login --insecure-storage let's you use gh as the source of the OAuth token.

For anyone struggling with this, spr tries to get the OAuth token from three sources:

  1. Environment variable GITHUB_TOKEN
  2. ~/.config/gh/hosts.yml
  3. ~/.config/hub

After gh release v2.26.0 logging in using gh auth login will no longer store the OAuth token as plain-text unless the --insecure-storage parameter is passed.

levibostian added a commit to levibostian/spr that referenced this issue Mar 7, 2024
As shared [in this comment](ejoffe#335 (comment)), gh cli has changed the default behavior of how github auth tokens are saved. This change makes spr no longer able to read github auth tokens and has caused myself and others confusion when instructions say to run `gh auth login` but still see spr not be able to find the token. 

This change updates the instructions to avoid this confusion. I do understand that suggesting to users to use insecure storage may not be ideal and a different solution may be preferred. Whatever solution it is, I believe it's better then today where users of spr receive these help docs, try them, and do not see success.
ejoffe pushed a commit that referenced this issue Mar 15, 2024
As shared [in this comment](#335 (comment)), gh cli has changed the default behavior of how github auth tokens are saved. This change makes spr no longer able to read github auth tokens and has caused myself and others confusion when instructions say to run `gh auth login` but still see spr not be able to find the token. 

This change updates the instructions to avoid this confusion. I do understand that suggesting to users to use insecure storage may not be ideal and a different solution may be preferred. Whatever solution it is, I believe it's better then today where users of spr receive these help docs, try them, and do not see success.
@carvierdotdev
Copy link

Hello everyone,

First off, I'd like to say that this tool is fantastic—great work!

I have a question regarding the selection options for scopes. Specifically, how many options should I select to appropriately define the access level for personal tokens?

Thank you for your assistance!

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

5 participants