Skip to content

Ask for read:org OAuth scope, warn for outdated tokens#786

Merged
vilmibm merged 5 commits intomasterfrom
oauth-read-org
Apr 29, 2020
Merged

Ask for read:org OAuth scope, warn for outdated tokens#786
vilmibm merged 5 commits intomasterfrom
oauth-read-org

Conversation

@mislav
Copy link
Copy Markdown
Contributor

@mislav mislav commented Apr 15, 2020

New tokens are requested with the read:org OAuth scope and old tokens are detected by having missing read:org scope and the user is asked to re-authenticate.

$ gh pr list
Warning: gh now requires the `read:org` OAuth scope.
To re-authenticate, please `rm ~/.config/gh/config.yml` and try again.

Showing 10 of 10 pull requests in cli/cli

#785  Update Debian instructions for modern apt versions        pabs3:debian-instructions
...

This is to facilitate:

Fixes #782

TODO:

  • Incorporate a less disruptive re-authentication flow

mislav added 2 commits April 15, 2020 14:28
This is to facilitate:
- requesting teams for review on `pr create`
- allowing `repo create ORG/REPO --team TEAM`
mislav added 2 commits April 23, 2020 15:35
How this works for people with existing OAuth tokens:

    $ gh issue list -L1
    Notice: additional authorization required
    Press Enter to open github.com in your browser...
    [auth flow in the browser...]
    Authentication complete. Press Enter to continue...

    Showing 1 of 132 issues in cli/cli
    ...

Users of Personal Access Tokens get a different notice:

    Warning: gh now requires the `read:org` OAuth scope.
    Visit https://github.com/settings/tokens and edit your token to enable `read:org`
    or generate a new token and paste it via `gh config set -h github.com oauth_token MYTOKEN`
@mislav mislav marked this pull request as ready for review April 23, 2020 16:21
@mislav
Copy link
Copy Markdown
Contributor Author

mislav commented Apr 23, 2020

This is now ready for review!

How this looks for people with existing OAuth tokens:

$ gh issue list -L1
Notice: additional authorization required
Press Enter to open github.com in your browser...
[auth flow in the browser...]
Authentication complete. Press Enter to continue...

Showing 1 of 132 issues in cli/cli
...

Users of Personal Access Tokens get a different notice:

Warning: gh now requires the `read:org` OAuth scope.
Visit https://github.com/settings/tokens and edit your token to enable `read:org`
or generate a new token and paste it via `gh config set -h github.com oauth_token MYTOKEN`

How to test this:

  1. Make a backup of your old token: cp ~/.config/gh/config.yml{,.bak}
  2. Run any gh command that hits the API
  3. Note the new token is now in ~/.config/gh/config.yml
  4. Restore your old config to potentially test again cp ~/.config/gh/config.yml{.bak,}

@mislav mislav requested review from probablycorey and vilmibm April 23, 2020 16:22
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 tried it out locally and it worked well. The code was a bit tricky to follow and I left some notes inline.

opts = append(opts,
api.AddHeader("Authorization", fmt.Sprintf("token %s", token)),
api.CheckScopes("read:org", checkScopesFunc),
api.AddHeaderFunc("Authorization", getAuthValue),
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.

It was a little tricky to follow the how the token var was being passed around here. The best way I could think of to make it simpler would be a scope check in the root command instead of using RoundTripper. But that has its own problems because you'd need to set some state once you've verified that the app has the correct permissions.

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.

It is complicated but I feel like it matches what we already have going on in the oauth code so it doesn't feel too out of place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely agree that it's complex how the token var is passed around this area of the code. This was a result of me jumping through hoops after realizing that, even though we write the new token to the config file, we didn't have any mechanism for updating the token in-memory during the lifetime of the CLI process. I haphazardly made such a mechanism here using closures, but it's not ideal and I will make a note to clean it up.

Co-Authored-By: Corey Johnson <probablycorey@gmail.com>
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.

Introduce a mechanism to request additional OAuth scopes with

3 participants