Skip to content

Instantly share code, notes, and snippets.

@daltonnyx
Created June 6, 2025 15:09
Show Gist options
  • Save daltonnyx/50837b2ac2c6a053f6d97aadc6627d1e to your computer and use it in GitHub Desktop.
Save daltonnyx/50837b2ac2c6a053f6d97aadc6627d1e to your computer and use it in GitHub Desktop.
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "requests",
# ]
# ///
import requests
import time
resp = requests.post(
"https://github.com/login/device/code",
headers={
"accept": "application/json",
"editor-version": "vscode/1.100.3",
"editor-plugin-version": "GitHub.copilot/1.330.0",
"content-type": "application/json",
"user-agent": "GithubCopilot/1.330.0",
"accept-encoding": "gzip,deflate,br",
},
data='{"client_id":"Iv1.b507a08c87ecfe98","scope":"read:user"}',
)
# Parse the response json, isolating the device_code, user_code, and verification_uri
resp_json = resp.json()
device_code = resp_json.get("device_code")
user_code = resp_json.get("user_code")
verification_uri = resp_json.get("verification_uri")
# Print the user code and verification uri
print(f"Please visit {verification_uri} and enter code {user_code} to authenticate.")
while True:
time.sleep(5)
resp = requests.post(
"https://github.com/login/oauth/access_token",
headers={
"accept": "application/json",
"editor-version": "vscode/1.100.3",
"editor-plugin-version": "GitHub.copilot/1.330.0",
"content-type": "application/json",
"user-agent": "GithubCopilot/1.330.0",
"accept-encoding": "gzip,deflate,br",
},
data=f'{{"client_id":"Iv1.b507a08c87ecfe98","device_code":"{device_code}","grant_type":"urn:ietf:params:oauth:grant-type:device_code"}}',
)
# Parse the response json, isolating the access_token
resp_json = resp.json()
access_token = resp_json.get("access_token")
if access_token:
break
print("Authentication success: " + access_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment