Skip to content

Commit

Permalink
Detect Github access token is not OAuth token in cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
holisHsu committed Apr 24, 2024
1 parent 5e89b8c commit c84407c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github_access_token_fine_grained
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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
11 changes: 10 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,23 @@ def setup():
headers = {"Authorization": f"token {github_access_token}"}
response = requests.get("https://api.github.com/user", headers=headers)
if response.status_code == 200:
scopes = response.headers.get("X-OAuth-Scopes")
o_auth_scopes_header = "X-OAuth-Scopes"
scopes = response.headers.get(o_auth_scopes_header, "")
if "public_repo" in scopes or "repo" in scopes:
click.echo(
click.style(
"✅ GitHub access token has the required permissions.",
fg="green",
)
)
elif o_auth_scopes_header not in response.headers:
install_error = True
click.echo(
click.style(
"❌ Response is lack of X-OAuth-Scopes, please make sure you use OAuth token.",
fg="red",
)
)
else:
install_error = True
click.echo(
Expand Down

0 comments on commit c84407c

Please sign in to comment.