forked from marksteve/flask-oauth2-login
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
34 lines (28 loc) · 735 Bytes
/
example.py
File metadata and controls
34 lines (28 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from flask import Flask, jsonify
from flask_oauth2_login import GoogleLogin
app = Flask(__name__)
app.config.update(
SECRET_KEY="secret",
GOOGLE_LOGIN_REDIRECT_SCHEME="http",
)
for config in (
"GOOGLE_LOGIN_CLIENT_ID",
"GOOGLE_LOGIN_CLIENT_SECRET",
):
app.config[config] = os.environ[config]
google_login = GoogleLogin(app)
@app.route("/")
def index():
return """
<html>
<a href="{}">Login with Google</a>
""".format(google_login.authorization_url())
@google_login.login_success
def login_success(token, profile):
return jsonify(token=token, profile=profile)
@google_login.login_failure
def login_failure(e):
return jsonify(error=str(e))
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)