Last active
August 29, 2015 14:20
-
-
Save Bachmann1234/fec472272ce79bb707d7 to your computer and use it in GitHub Desktop.
facebook flask-dance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, url_for, redirect | |
from flask_dance.consumer import OAuth2ConsumerBlueprint | |
app = Flask(__name__) | |
app.secret_key = "<ISHOULDBESOMETHING>" | |
batman_example = OAuth2ConsumerBlueprint( | |
"batman-example", __name__, | |
client_id="<CLIENT_ID>", | |
client_secret="<SECRET>", | |
base_url="https://graph.facebook.com", | |
authorization_url="https://www.facebook.com/dialog/oauth", | |
token_url="https://graph.facebook.com/oauth/access_token", | |
) | |
app.register_blueprint(batman_example, url_prefix="/login") | |
@app.route("/") | |
def index(): | |
if not batman_example.session.authorized: | |
return redirect(url_for("batman-example.login")) | |
resp = batman_example.session.get("me") | |
assert resp.ok | |
return resp.text | |
if __name__ == "__main__": | |
app.run(port=8080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment