· 6 years ago · Mar 18, 2019, 10:50 PM
1'''
2Client OAuth Settings:
3 Client OAuth Login: Yes
4 Web OAuth Login: Yes
5 Enforce HTTPS: Yes
6 Use Strict Mode for Redirect URIs: Yes
7 Valid OAuth Redirect URIs: https://cffbot.pagekite.me/login/authorized?next=https://cffbot.pagekite.me/
8App Settings:
9 App Domains: pagekite.me pagekite.net
10 Site URL: https://cffbot.pagekite.me/
11
12
13pageKite:
14$ pagekite 8000 cffbot.pagekite.me
15>>> Hello! This is pagekite v0.5.9.3. [CTRL+C = Stop]
16 Connecting to front-end relay 94.130.76.112:443 ...
17 - Protocols: http http2 http3 https websocket irc finger httpfinger raw
18 - Protocols: minecraft
19 - Ports: 79 80 443 843 2222 3000 4545 5222 5223 5269 5670 6667 8000 8080
20 - Ports: 8081 8082 8083 9292 25565
21 - Raw ports: virtual
22 Quota: You have 2553.70 MB, 31 days and 5 connections left.
23 Connecting to front-end relay 172.104.252.209:443 ...
24~<> Flying localhost:8000 as https://cffbot.pagekite.me/
25 197.2.43.64 < http://cffbot.pagekite.me:443 (localhost:8000)
26 << pagekite.py [flying] Kites are flying and all is well.
27
28
29Error when login to facebook using python code:
30127.0.0.1 - - [18/Mar/2019 17:43:33] "GET /login/authorized?next=https%3A%2F%2Fcffbot.pagekite.me%2F&code=AQB17j28celeXNFjC1Dq6W4KT5GbSlnZ8ISxofLN7gWpU1Vqpoe9qX4BeIoElmaUIWhiRmO6EyYEudO-b6t6kZ1Cm1RAwwzTzWvlNIYkA2fJxKzVny2lhhzywe93sEruanfKANZ782asZ3gfZdtEk4ZR1XZZ-l8Ljpb_fwpZchGMXPu4K9PDFBmCY-1o2LEbuCOTVodJo9O8ImNGp3Jz-YWStaCkSn1h72IK0vdalQkdgajdZ_ITUgdlz-IfyVqeIun0SCJmfYCzOlvYmZFEAFlTxaDcVnID-bYnEqarcAi3Ssgy9kWlpyLg4a_uYvDg-zPaztBsq9-lp92aL4ISTorP HTTP/1.1" 500 -
31Traceback (most recent call last):
32 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
33 return self.wsgi_app(environ, start_response)
34 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
35 response = self.handle_exception(e)
36 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
37 reraise(exc_type, exc_value, tb)
38 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
39 raise value
40 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
41 response = self.full_dispatch_request()
42 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
43 rv = self.handle_user_exception(e)
44 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
45 reraise(exc_type, exc_value, tb)
46 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
47 raise value
48 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
49 rv = self.dispatch_request()
50 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
51 return self.view_functions[rule.endpoint](**req.view_args)
52 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask_oauthlib/client.py", line 728, in decorated
53 data = self.authorized_response()
54 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask_oauthlib/client.py", line 707, in authorized_response
55 data = self.handle_oauth2_response(args)
56 File "/home/mourad/my-virtualenv-for-python3/lib/python3.6/site-packages/flask_oauthlib/client.py", line 692, in handle_oauth2_response
57 type='invalid_response', data=data
58flask_oauthlib.client.OAuthException: Invalid response from facebook
59
60'''
61
62
63from flask import Flask, redirect, url_for, session, request, render_template
64from flask_oauthlib.client import OAuth
65
66FACEBOOK_GRAPH_URL = 'https://graph.facebook.com/v3.2'
67
68FACEBOOK_APP_ID = '****'
69FACEBOOK_APP_SECRET = '****'
70REDIRECT_URI = '/oauth2callback'
71
72SECRET_KEY = '****'
73DEBUG = True
74
75app = Flask(__name__)
76app.config['SECRET_KEY'] = SECRET_KEY
77app.config['DEBUG'] = DEBUG
78
79oauth = OAuth()
80
81fb = oauth.remote_app('facebook',
82 base_url='https://www.facebook.com/',
83 authorize_url='https://www.facebook.com/v3.2/dialog/oauth',
84 request_token_url=None,
85 request_token_params={'scope': ('email', 'public_profile', 'pages_show_list', )},
86 access_token_url='https://graph.facebook.com/v3.2/oauth/access_token',
87 access_token_method='GET',
88 consumer_key=FACEBOOK_APP_ID,
89 consumer_secret=FACEBOOK_APP_SECRET)
90
91
92@app.route('/', methods=['GET'])
93def index1():
94 if request.args.get('hub.mode') == 'subscribe' and request.args.get('hub.challenge'):
95 if not request.args.get('hub.verify_token') == 'incoming-comment':
96 return "not ok", 403
97 return request.args.get('hub.challenge'), 200
98
99 return render_template("index1.html")
100
101@fb.tokengetter
102def get_facebook_oauth_token():
103 return session.get('oauth_token')
104
105@app.route('/login')
106def login():
107 return fb.authorize(callback=url_for('facebook_authorized', next=request.args.get('next') or request.referrer or None, _external=True))
108
109
110@app.route('/login/authorized')
111@fb.authorized_handler
112def facebook_authorized(resp):
113 # Handle the login request response
114 print("///////////*****************************")
115 print(resp)
116 if resp == None:
117 print("oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
118 print(request.args['error_reason'] + '\n' + request.args['error_description'])
119 return '', 204
120 else:
121 # Getting user access token
122 session['oauth_token'] = (resp['access_token'], '')
123 user_access_token = session['oauth_token'][0]
124
125 if user_access_token == None:
126 socketio.emit('try_to_login', {'data': '\t Can not get user access token.'}, broadcast=True)
127 return '', 204
128
129 print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
130 print(user_access_token)
131 print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
132
133
134
135
136 return redirect("https://www.facebook.com/")
137
138
139if __name__ == "__main__":
140 app.run(debug=True, port=8000)