2

我正在使用 flask-oauth 来验证我的用户。

我做了一些挖掘,发现这是flask-oauth发送的URL:

https://www.facebook.com/dialog/oauth?response_type=code&client_id=1000000000000&redirect_uri=http%3A%2F%2Fwww.resoorce.com%2Flogin%2Fauthorized&scope=email

它显然有一个 redirect_uri 参数!

这是 facebook 发回的响应:

{"error":{"message":"Missing redirect_uri parameter.","type":"OAuthException","code":191}}

如果有帮助,这是我的全部代码:

from flask import Flask, redirect, url_for, session, request
from flask_oauthlib.client import OAuth, OAuthException

'''fake ones'''
FACEBOOK_APP_ID = '123121321212312313'
FACEBOOK_APP_SECRET = 'dfg12sdf1g2s1dfg31sd3fg'


app = Flask(__name__)
app.debug = True
app.secret_key = 'development'
oauth = OAuth(app)

facebook = oauth.remote_app(
    'facebook',
    consumer_key=FACEBOOK_APP_ID,
    consumer_secret=FACEBOOK_APP_SECRET,
    request_token_params={'scope': 'email'},
    base_url='https://graph.facebook.com',
    request_token_url=None,
    access_token_url='/oauth/access_token',
    authorize_url='https://www.facebook.com/dialog/oauth'
)


@app.route('/')
def index():
    return redirect(url_for('login'))


@app.route('/login')
def login():
    callback = url_for(
        'facebook_authorized',
        next=request.args.get('next') or request.referrer or None,
        _external=True
    )
    return facebook.authorize(callback=callback)


@app.route('/login/authorized')
@facebook.authorized_handler
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %s' % resp.message

    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    return 'Logged in as id=%s name=%s redirect=%s' % \
        (me.data['id'], me.data['name'], request.args.get('next'))


@facebook.tokengetter
def get_facebook_oauth_token():
    return session.get('oauth_token')
ain__':
    app.run()

if __name__ == '__main__':
    app.run()
4

0 回答 0