-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (26 loc) · 1.03 KB
/
main.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
from flask import Flask, request, jsonify, send_from_directory
import requests
import os
SYNAPSE_API = "https://synapse-api.replit.app/api"
# replace this by your Synapse Application credentials
CLIENT_ID = "test_app"
CLIENT_SECRET = os.getenv("SYNAPSE_SECRET")
app = Flask(__name__)
# main route for Synapse authorization
@app.route("/synapse/token", methods=["GET"])
def synapse_token():
url = f"{SYNAPSE_API}/token?code={request.args.get('code')}"
response = requests.get(url, headers={
"Authorization": f"Basic {CLIENT_ID}:{CLIENT_SECRET}"
})
# a JSON object is returned with token or error
return jsonify(response.json())
# static files (html, css, ...) served from /public
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def serve_static_files(path):
path = path if path != "" and path is not None else "index.html"
static_dir = os.path.join(os.getcwd(), "public")
return send_from_directory(static_dir, path)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)