I have a Flask app that I'm trying to authenticate with Facebook. Locally, it works perfectly fine. When I deploy to Heroku, it doesn't work, throwing 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 over stackoverflow and google for the answer to this, but I can't seem to figure it out.
I'm particularly confused as to why it's working locally and not deployed.
As for my implementation, it's to the 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 clues?
Try making your callback URL a full url with domain, etc. If you're working locally, you can use localhost, but specify the port if you're not on 80.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With