Skip to content

Respect GITHUB_TOKEN environment variable#976

Merged
mislav merged 6 commits intomasterfrom
auth-from-env
May 27, 2020
Merged

Respect GITHUB_TOKEN environment variable#976
mislav merged 6 commits intomasterfrom
auth-from-env

Conversation

@mislav
Copy link
Copy Markdown
Contributor

@mislav mislav commented May 20, 2020

In browsers where users would prefer to skip interactive authentication flow, or where such an interaction is not available (e.g. there is no graphical browser), users may set their authentication token via the GITHUB_TOKEN environment variable.

export GITHUB_TOKEN="..."
gh issue list  #=> uses GITHUB_TOKEN, ignores config file

Ref. #297 #773

Combines well with #909

TODO:

mislav added 2 commits May 20, 2020 17:09
The login name of the authenticated user will be readily available only
if authentication info comes from the config file. With other upcoming
authentication modes (for example, the GITHUB_TOKEN environment
variable), the token is the only piece of information we got, so we
would need to additionally query for the login name.

Since `issue status` and `pr status` are the only commands that need the
name of the authenticated user right now, have those commands explicitly
query for the login name. This results in an additional API query, but
simplifies Context implementation and future authentication approaches.
If GITHUB_TOKEN is non-blank, it overrides authentication info found in
the config file. The config file is, in fact, never consulted.
@mislav mislav requested review from probablycorey and vilmibm May 20, 2020 15:40
Copy link
Copy Markdown
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I especially appreciate the attention to detail when printing auth notices.

Just to confirm two things:

  • we're introducing username lookup latency for some commands. do you have a sense of what amount of latency it is?
  • is there a point anymore of storing a username in the config file anymore?

@mislav
Copy link
Copy Markdown
Contributor Author

mislav commented May 22, 2020

  • we're introducing username lookup latency for some commands. do you have a sense of what amount of latency it is?

Thanks for calling this out; I should have pointed this out in the PR description! The latency of the extra request is 180–500ms for me.

We can avoid this extra request in pr status by always using the special keyword @me instead of the actual username. However, @me won't work in issue status because we're using a different API there that is not based on ElasticSearch.

  • is there a point anymore of storing a username in the config file anymore?

Also a great question! Probably not, but I thought that we best visit this in follow up as we address either #449, #326, or #937.

Copy link
Copy Markdown
Contributor

@probablycorey probablycorey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little worried about the additional user query at first, but it looks like we only need the user name in our two status commands (and PR can use the magic @me trick)

So it looks good to me.

fmt.Fprintln(os.Stderr, "or generate a new token for the GITHUB_TOKEN environment variable")
} else {
fmt.Fprintln(os.Stderr, "or generate a new token and paste it via `gh config set -h github.com oauth_token MYTOKEN`")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a little weird about continuing to put username in the config after this but not weird enough to insist we stop and deal with it now.

@kumarz
Copy link
Copy Markdown

kumarz commented Aug 4, 2020

I used GITHUB_TOKEN environment variable for PAT and I was able to successfully clone repo and get authenticated.

Shall I assume, when it comes to github app tokens, using the GITHUB_TOKEN environment variable will work too ? or is there anything else that needs to be done for this to work

@mislav
Copy link
Copy Markdown
Contributor Author

mislav commented Aug 5, 2020

If you have a GitHub Apps token, please supply that as GITHUB_TOKEN, check if it works, and if anything breaks please report to #1489. We would be grateful!

@kumarz
Copy link
Copy Markdown

kumarz commented Aug 5, 2020

If you have a GitHub Apps token, please supply that as GITHUB_TOKEN, check if it works, and if anything breaks please report to #1489. We would be grateful!

will there be any difference or things that I should watch out for using GITHUB_TOKEN with other than PAT ?

@mislav
Copy link
Copy Markdown
Contributor Author

mislav commented Aug 6, 2020

@kumarz I believe everything should work, but there was a bug reported that requesting team reviewers on a newly created PR did not work using a server-to-server integration token #1314

So when something mysteriously breaks like that, please let us know.

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

Successfully merging this pull request may close these issues.

4 participants