This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
64 lines (49 loc) · 1.59 KB
/
server.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, url_for, request
from github import Github
app = Flask(__name__)
CLIENT_ID = "ef2350442ef233ab666c"
CLIENT_SECRET = "680a3834b54e58171157d73b2a752f1053254a59"
REDIRECT_URI = "http://localhost:5000/build"
@app.route('/')
def homepage():
text = '<a href="%s">Authenticate with github</a>'
return text % make_authorization_url()
def make_authorization_url():
# Generate a random string for the state parameter
# Save it for use later to prevent xsrf attacks
from uuid import uuid4
state = str(uuid4())
save_created_state(state)
params = {"client_id": CLIENT_ID,
"response_type": "code",
"state": state,
"redirect_uri": REDIRECT_URI,
"duration": "temporary",
"scope": "identity"}
import urllib
url = "https://github.com/login/oauth/authorize?" + urllib.urlencode(params)
return url
# Left as an exercise to the reader.
# You may want to store valid states in a database or memcache,
# or perhaps cryptographically sign them and verify upon retrieval.
def save_created_state(state):
pass
def is_valid_state(state):
return True
'''
@app.route('/')
def api_root():
return 'Welcome'
'''
@app.route('/build')
def api_list():
out = ""
g = Github( request.args.get('code') )
for repo in g.get_user().get_repos():
out += repo.name + "\n"
return 'List of ' + url_for('api_list') + "\n\n" + out
@app.route('/build/<repo>')
def api_build(repo):
return 'You are reading ' + repo
if __name__ == '__main__':
app.run(debug=True, port=5000)