-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
82 lines (58 loc) · 2.05 KB
/
app.py
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
78
79
80
81
82
import os
import pprint
import urllib
import uuid
from tempfile import mkdtemp
from flask import Flask, render_template, jsonify
from flask import redirect, request
from flask_caching import Cache
from pylti1p3.contrib.flask import FlaskMessageLaunch, FlaskOIDCLogin, FlaskRequest, FlaskCacheDataStorage
from pylti1p3.tool_config import ToolConfJsonFile
import Config as config
import RestController
import RestAuthController
## TODO
PAGE_TITLE = 'Title'
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
scheme = environ.get('HTTP_X_FORWARDED_PROTO')
if scheme:
environ['wsgi.url_scheme'] = scheme
return self.app(environ, start_response)
app = Flask('LTI-Workshop', template_folder='templates', static_folder='static')
app.wsgi_app = ReverseProxied(app.wsgi_app)
app.config.from_mapping(config.tool_config)
cache = Cache(app)
class ExtendedFlaskMessageLaunch(FlaskMessageLaunch):
def validate_nonce(self):
"""
Probably it is bug on "https://lti-ri.imsglobal.org":
site passes invalid "nonce" value during deep links launch.
Because of this in case of iss == http://imsglobal.org just skip nonce validation.
"""
iss = self.get_iss()
deep_link_launch = self.is_deep_link_launch()
if iss == "http://imsglobal.org" and deep_link_launch:
return self
return super(ExtendedFlaskMessageLaunch, self).validate_nonce()
def get_lti_config_path():
return os.path.join(app.root_path, 'lti.json')
def get_launch_data_storage():
return FlaskCacheDataStorage(cache)
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('helloworld.html')
@app.route('/login/', methods=['GET', 'POST'])
def login():
return
@app.route('/launch/', methods=['HEAD', 'GET', 'POST'])
def launch():
return
@app.route('/jwks/', methods=['GET'])
def get_jwks():
return
if __name__ == '__main__':
restAuthController = None
app.run(host='0.0.0.0', port=5000)