-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_dance.py
More file actions
77 lines (60 loc) · 1.95 KB
/
example_dance.py
File metadata and controls
77 lines (60 loc) · 1.95 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Flask-Dance example.
This example demonstrates how to integrate a server application with
Authentiq Connect. It uses the popular Flask-Dance package to make
this trivial in Flask.
"""
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals
)
import os
from flask import Flask, redirect, url_for
from flask_dance.contrib.authentiq import make_authentiq_blueprint, authentiq
from werkzeug.contrib.fixers import ProxyFix
class Config(object):
"""
Flask configuration container.
"""
DEBUG = True
TESTING = False
SECRET_KEY = "aicahquohzieRah5ZooLoo3a"
# The following app is registered at Authentiq Connect.
CLIENT_ID = os.environ.get("CLIENT_ID", "examples-flask-basic")
CLIENT_SECRET = os.environ.get("CLIENT_SECRET", "ed25519")
# Personal details requested from the user. See the "scopes_supported" key in
# the following JSON document for an up to date list of supported scopes:
#
# https://connect.authentiq.io/.well-known/openid-configuration
#
REQUESTED_SCOPES = ["openid", "aq:name", "email~s", "aq:push", "userinfo"]
PORT = 8000
REDIRECT_URL = "http://localhost:%d/authorized" % PORT
app = Flask(__name__)
app.config.from_object(Config)
app.wsgi_app = ProxyFix(app.wsgi_app)
blueprint = make_authentiq_blueprint(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=" ".join(REQUESTED_SCOPES),
)
app.register_blueprint(blueprint, url_prefix="/login")
@app.route("/")
def index():
if not authentiq.authorized:
return redirect(url_for("authentiq.login"))
resp = authentiq.get("/userinfo")
assert resp.ok
data = resp.json()
return "You are {name} on Authentiq!".format(
name=data.get("name") or data.get("email") or "anonymous")
if __name__ == "__main__":
if app.debug:
import os
# Allow insecure oauth2 when debugging
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
app.run()