为Flask应用提供OAuth支持:Flask-Dance

jopen 9年前

内置了 OAuth 支持, 以便我们的 Flask 应用接入 oauthlib 以及相关请求。只有消费者的OAuth支持,但这个项目可以很容易地支持OAuth的提供者在未来。

from flask import Flask, redirect, url_for  from flask_dance.contrib.github import make_github_blueprint, github    app = Flask(__name__)  app.secret_key = "supersekrit"  blueprint = make_github_blueprint(      client_id="my-key-here",      client_secret="my-secret-here",      redirect_to="index",  )  app.register_blueprint(blueprint, url_prefix="/login")    @app.route("/")  def index():      if not github.authorized:          return redirect(url_for("github.login"))      resp = github.get("/user")      assert resp.ok      return "You are @{login} on Github".format(login=resp.json()["login"])    if __name__ == "__main__":      app.run()

项目主页:http://www.open-open.com/lib/view/home/1414719629059