feat: oidc support

This commit is contained in:
2023-01-08 18:49:50 +01:00
parent 486f919670
commit 05478e39cc

View File

@@ -5,8 +5,21 @@ import argparse
import sys
import PIL.Image
import werkzeug.utils
import flask_oidc
import json
app = flask.Flask("Picture factory app", static_folder=None)
## OIDC CONFIG SETUP ##
if os.path.isfile("oidc.json"):
with open("oidc.json") as f:
app.config |= json.load(f)
if not os.path.isfile("client_secrets.json"):
raise ValueError("client_secrets.json file is missing in project root")
else:
raise ValueError("OIDC required by environment but not oidc.json file found")
oidc = flask_oidc.OpenIDConnect(app)
PICTURE_DIR = "pictures/"
def generatePicture(pathToOrig, scaleX, scaleY, encoding, crop):
@@ -136,6 +149,7 @@ def list():
return flask.render_template("index.html", paths=retStringArr)
@app.route("/upload", methods = ['GET', 'POST'])
@oidc.require_login
def upload():
if not app.config['UPLOAD_ENABLED']:
return ("Upload Disabled", 403)
@@ -161,6 +175,7 @@ def init():
app.config['UPLOAD_FOLDER'] = PICTURE_DIR
app.config['UPLOAD_ENABLED'] = os.path.isfile("./upload.enable")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Picture Factory',