Created
July 22, 2018 08:47
-
-
Save bussiere/ab74419004d93c39c5703e64f82ea1f7 to your computer and use it in GitHub Desktop.
Get an Oauth2 token from github with python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
#r = requests.get('https://composcan-api-dev.herokuapp.com/v1/products', json={"_id": "auth0|5a65b0c09f5e2b5157614782","ea" : "3517360013542"}) | |
#print(r.content) | |
#print(r.json()) | |
GITHUB_API = 'https://api.github.com' | |
import requests | |
import getpass | |
import json | |
from urllib.parse import urljoin | |
def main(): | |
# | |
# User Input | |
# | |
username = 'toto' | |
password = 'georgesAbitbol' | |
note = "hou" | |
# | |
# Compose Request | |
# | |
url = urljoin(GITHUB_API, 'authorizations') | |
payload = {} | |
if note: | |
payload['note'] = note | |
res = requests.post( | |
url, | |
auth = (username, password), | |
data = json.dumps(payload), | |
) | |
# | |
# Parse Response | |
# | |
j = json.loads(res.text) | |
print(j) | |
token = j['token'] | |
print('New token: %s' % token) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment