-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathgithub-cli.py
29 lines (22 loc) · 1.11 KB
/
github-cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from rauth.service import OAuth2Service
# Get a real consumer key & secret from:
# https://github.com/settings/applications/new
github = OAuth2Service(
client_id='8ae4946cc5a9af76f6d7',
client_secret='48aeb2b3c9226ae2b698eef4d7e6310473ccafa7',
name='github',
authorize_url='https://github.com/login/oauth/authorize',
access_token_url='https://github.com/login/oauth/access_token',
base_url='https://api.github.com/')
print 'Visit this URL in your browser: ' + github.get_authorize_url()
# This is a bit cumbersome, but you need to copy the code=something (just the
# `something` part) out of the URL that's redirected to AFTER you login and
# authorize the demo application
code = raw_input('Enter code parameter (code=something) from URL: ')
# create a dictionary for the data we'll post on the get_access_token request
data = dict(code=code, redirect_uri='https://github.com/litl/rauth/')
# retrieve the authenticated session
session = github.get_auth_session(data=data)
# make a request using the authenticated session
user = session.get('user').json()
print 'currently logged in as: ' + user['login']