我有一个 Flask 应用程序,我正在尝试通过 Facebook 进行身份验证。在本地,它工作得非常好。当我部署到 Heroku 时,它不起作用,抛出以下错误:
{u'error': {u'type': u'OAuthException', u'message': u'Missing redirect_uri parameter.', u'code': 191}}
'Invalid response from facebook'
我已经在 stackoverflow 和谷歌上搜索了这个问题的答案,但我似乎无法弄清楚。
我对为什么它在本地工作而不是部署感到特别困惑。
至于我的实施,这是信中的:
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')
有人有任何线索吗?