OCID compatiblity

This commit is contained in:
Tracker-Friendly 2024-03-28 17:51:21 +00:00
parent 42ca222049
commit 9f8512da18
2 changed files with 21 additions and 4 deletions

22
main
View File

@ -193,6 +193,21 @@ async def apiuserinfo():
} }
return datatemplate return datatemplate
@app.route("/userinfo", methods=("GET", "POST"))
async def apiopeniduserinfo():
if request.method == "GET":
access_token = request.headers.get('Authorization').split(' ')[1]
conn = get_db_connection()
userid = int(conn.execute("SELECT creator FROM logins WHERE code = ?", (str(access_token))).fetchone())
user = get_user(userid)
datatemplate = {
"sub": user["username"],
"name": user["username"]
}
return datatemplate
@app.route("/api/auth", methods=("GET", "POST")) @app.route("/api/auth", methods=("GET", "POST"))
async def apiauthenticate(): async def apiauthenticate():
if request.method == "POST": if request.method == "POST":
@ -210,8 +225,8 @@ async def apiauthenticate():
if not str(clientidcheck) == str(appId): if not str(clientidcheck) == str(appId):
return {}, 401 return {}, 401
conn.execute("INSERT INTO logins (appId, authed, secret, code, nextcode, creator) VALUES (?, ?, ?, ?, ?, ?)", conn.execute("INSERT INTO logins (appId, authed, secret, code, nextcode, creator, openid) VALUES (?, ?, ?, ?, ?, ?, ?)",
(str(appId), int(int(time.time()) + 3600), int(0), str(secretkey), str(secrets.token_hex(512)), str(secrets.token_hex(512)), int(user["id"]))) (str(appId), int(int(time.time()) + 3600), int(0), str(secretkey), str(secrets.token_hex(512)), str(secrets.token_hex(512)), int(user["id"]), str(secrets.token_hex(512))))
conn.commit() conn.commit()
conn.close() conn.close()
@ -233,7 +248,8 @@ async def apitokenexchange():
"access_token": str(conn.execute("SELECT secret FROM logins WHERE appId = ? AND code = ?", (str(appId), str(code))).fetchone()), "access_token": str(conn.execute("SELECT secret FROM logins WHERE appId = ? AND code = ?", (str(appId), str(code))).fetchone()),
"token_type": "bearer", "token_type": "bearer",
"expires_in": 3600, "expires_in": 3600,
"refresh_token": str(conn.execute("SELECT nextcode FROM logins WHERE appId = ? AND code = ?", (str(appId), str(code))).fetchone()) "refresh_token": str(conn.execute("SELECT nextcode FROM logins WHERE appId = ? AND code = ?", (str(appId), str(code))).fetchone()),
"id_token": str(conn.execute("SELECT openid FROM logins WHERE appId = ? AND code = ?", (str(appId), str(code))).fetchone())
} }
clientidcheck = str(conn.execute("SELECT appId FROM oauth WHERE appId = ?", (str(appId)))).fetchone() clientidcheck = str(conn.execute("SELECT appId FROM oauth WHERE appId = ?", (str(appId)))).fetchone()

View File

@ -28,5 +28,6 @@ CREATE TABLE logins (
secret TEXT NOT NULL, secret TEXT NOT NULL,
code TEXT NOT NULL, code TEXT NOT NULL,
nextcode TEXT NOT NULL, nextcode TEXT NOT NULL,
creator INTEGER NOT NULL creator INTEGER NOT NULL,
openid TEXT NOT NULL
) )