我试图与自定义Oauth提供商一起使用烧瓶dance oauth。但是,当我尝试使用授权:使用自定义提供商使用oauth的github:councel_info.ok nes councel_info.ok inter ofers counce_info.ok inters oint offers infals。我想做的是使用自定义提供商,我将能够授权任何可用的OAuth提供商。我不知道如何使用http://flask-dance.readthedocs.io/en/latest/providers.html#custom上提到的自定义提供商这是我的代码:
from flask import Flask
from flask_dance.consumer import OAuth2ConsumerBlueprint
from flask import Flask, redirect, url_for
#export OAUTHLIB_INSECURE_TRANSPORT=1
app = Flask(__name__)
app.config['SECRET_KEY']='thisissupposedtobesecretkey'
client_id = "*********************",
client_secret = "********************",
example_blueprint = OAuth2ConsumerBlueprint("github", __name__,
client_id=client_id,
client_secret=client_secret,
scope=None,
base_url="https://api.github.com/",
authorization_url="https://github.com/login/oauth/authorize",
token_url="https://github.com/login/oauth/access_token",
redirect_url=None,
redirect_to=None,
login_url=None,
authorized_url=None,
session_class=None,
backend=None,
)
app.register_blueprint(example_blueprint, url_prefix="/login")
@app.route('/example')
def login():
if not example_blueprint.authorized:
return redirect(url_for('example_blueprint.login'))
try:
account_info=example_blueprint.session.get("/user")
print "i m here ....."
print account_info.ok
return account_info
except Exception as e:
print "i m here .....",e
#
if __name__=='__main__':
app.run(debug=True)
您需要从OAuth2Session实例调用授权方法,该实例会自动从存储中加载OAuth提供商的代币。因此,您需要更改以下代码行:
@app.route('/example')
def login():
if not example_blueprint.authorized:
return redirect(url_for('example_blueprint.login'))
to
@app.route('/example')
def login():
if not example_blueprint.session.authorized:
return redirect(url_for('example_blueprint.login'))
欢呼