I am trying to deploy my application on PythonAnywhere but I am unable to set up the Flask-Stormpath Facebook login.
The email based login and Google connect are working fine, but Facebook login is not working. I have updated the Facebook app to the correct application url and verified that Facebook connect does work on localhost.
2016-04-14 18:08:07,121 :Exception on /facebook [GET]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/btpraasta/.local/lib/python2.7/site-packages/flask_stormpath/views.py", line 265, in facebook_login
current_app.config['STORMPATH_SOCIAL']['FACEBOOK']['app_secret'],
File "/usr/local/lib/python2.7/dist-packages/facebook.py", line 497, in get_user_from_cookie
app_id, app_secret)
File "/usr/local/lib/python2.7/dist-packages/facebook.py", line 581, in get_access_token_from_code
response = json.loads(response)
File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 488, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 389, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Here are the configuration for StormPath that I am using :-
# Stormpath app configuration
app.config['STORMPATH_API_KEY_FILE'] = '/home/btpraasta/btp_raasta/stormpath/apiKey.properties'
app.config['STORMPATH_API_KEY_FILE'] = 'stormpath/apiKey.properties'
app.config['STORMPATH_APPLICATION'] = 'Raasta'
app.config['STORMPATH_REDIRECT_URL'] = '/redirecting'
app.config['STORMPATH_REGISTRATION_REDIRECT_URL'] = '/verifyEmail'
app.config['STORMPATH_REGISTRATION_TEMPLATE'] = 'register.html'
app.config['STORMPATH_LOGIN_TEMPLATE'] = 'login.html'
app.config['STORMPATH_FORGOT_PASSWORD_TEMPLATE'] = 'forgot.html'
app.config['STORMPATH_ENABLE_MIDDLE_NAME'] = False
app.config['STORMPATH_ENABLE_USERNAME'] = True
app.config['STORMPATH_REQUIRE_USERNAME'] = True
app.config['STORMPATH_ENABLE_FORGOT_PASSWORD'] = True
app.config['STORMPATH_ENABLE_FACEBOOK'] = True
app.config['STORMPATH_ENABLE_GOOGLE'] = True
app.config['STORMPATH_SOCIAL'] = {
'FACEBOOK': {
'app_id': 'xxxxx',
'app_secret': 'xxxxx',
},
'GOOGLE': {
'client_id': 'xxxxx',
'client_secret': 'xxxxxx',
}
}
The client_id and client_secret have been hidden. The same configuration does work on the localhost.
The error was due to Facebook-SDK version 0.4 which did not have output proxy support. Raised a ticked and now Flask-Stormpath uses Facebook-SDK version 1.0 which supports the same.
If you still face the same issue update your Flask-Stormpath :-
pip install --upgrade flask-stormpath