Flask / Facebook: Flask-Oauth OAuthException: Missing redirect_uri parameter?
I have a Flask application that I am trying to execute using Facebook. Locally it works fine. When I deploy to Heroku it doesn't work causing the following error:
{u'error': {u'type': u'OAuthException', u'message': u'Missing redirect_uri parameter.', u'code': 191}}
'Invalid response from facebook'
I've searched all stackoverflow and google for an answer to this question, but I can't figure out how to do it.
I am especially confused as to why it works locally and is not deployable.
As for my implementation, this letter:
facebook = oauth.remote_app('facebook',
base_url='https://graph.facebook.com/',
request_token_url=None,
access_token_url='/oauth/access_token',
authorize_url='https://www.facebook.com/dialog/oauth',
consumer_key=FACEBOOK_APP_ID,
consumer_secret=FACEBOOK_APP_SECRET,
request_token_params={'scope':'email,user_birthday,user_education_history,user_photos,publish_actions'}
)
@app.route('/login')
def login():
return facebook.authorize(callback=url_for('facebook_authorized',
next=request.args.get('next') or request.referrer or None,
_external=True))
@app.route('/login/authorized')
@facebook.authorized_handler
def facebook_authorized(resp):
if resp is None:
error = 'Access denied: reason=%s error=%s' %(
request.args['error_reason'],
request.args['error_descriptions']
)
return render_template('home.html', error=error)
xyz = (resp['access_token'], '')
session['oauth_token'] = xyz
me = facebook.get('/me')
checkUser = db.session.query(User).filter(User.fid==me.data['id']).all()
if not checkUser:
fname = me.data['name'].split()[0]
lname = me.data['name'].split()[-1]
education=''
if 'education' in me.data:
education=me.data['education'][-1]['school']['name']
newuser = User(me.data['id'], fname, lname, me.data['email'], me.data['username'], education)
db.session.add(newuser)
db.session.commit()
flash('You were logged in')
session['fid'] = me.data['id']
return redirect(url_for('home'))
@facebook.tokengetter
def get_facebook_oauth_token():
return session.get('oauth_token')
Anyone have any hints?
+3
source to share