From 64818f1e6e4a4eacfd7aff17a23737a60f43a3c9 Mon Sep 17 00:00:00 2001 From: arzumify Date: Tue, 14 May 2024 01:23:03 +0100 Subject: [PATCH] OAuth2 build working --- config.ini | 8 +-- main | 12 ++-- templates/oauth.html | 142 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 8 deletions(-) create mode 100644 templates/oauth.html diff --git a/config.ini b/config.ini index 596f2a9..e39be9f 100644 --- a/config.ini +++ b/config.ini @@ -1,6 +1,6 @@ [config] -PORT = 8080 -SECRET_KEY = placeholder +PORT = 8083 +SECRET_KEY = illaaaaaaaaaaaaaaaaaaaaaaaaaaoewhoihowheowheowheow UPLOAD_FOLDER = uploads -PASSWORD_REQUIREMENT = 12 -UPLOAD_LIMIT = 12 \ No newline at end of file +PASSWORD_REQUIREMENT = 8 +UPLOAD_LIMIT = 8 diff --git a/main b/main index b1cab51..a1d2c67 100644 --- a/main +++ b/main @@ -388,13 +388,15 @@ async def apilogin(): }, 400 @app.route("/api/oauth", methods=("GET", "POST")) -async def apilogin(): +async def apioauth(): if request.method == "POST": data = await request.get_json() username = data["username"] password = data["access_token"] - response = requests.post("https://auth.hectabit.org/api/loggedin", {"access_token": password}) + conn = get_db_connection() + subdata = '{"access_token":"' + password + '"}' + response = requests.post("https://auth.hectabit.org/api/loggedin", subdata) if response.status_code == 200: userID = check_username_taken(username) user = get_user(userID) @@ -402,11 +404,10 @@ async def apilogin(): conn.execute("INSERT INTO users (username, password, created, htmldescription) VALUES (?, ?, ?, ?)", (username, "OAUTH2", str(time.time()), "")) else: - return {"error": "oauth2 token error"}, response.status_code + return {"error": response.json()["error"]}, response.status_code randomCharacters = secrets.token_hex(512) - conn = get_db_connection() conn.execute("INSERT INTO sessions (session, id) VALUES (?, ?)", (randomCharacters, userID)) conn.commit() @@ -625,6 +626,9 @@ async def login(): else: return await render_template("login.html") +@app.route("/oauth", methods=("GET", "POST")) +async def oauth(): + return await render_template("oauth.html") @app.route("/settings", methods=("GET", "POST")) async def settings(): diff --git a/templates/oauth.html b/templates/oauth.html new file mode 100644 index 0000000..2aacea5 --- /dev/null +++ b/templates/oauth.html @@ -0,0 +1,142 @@ + + + + + + OAuth2 Test + + +

Login using OAuth2

+ + + + +