Add support for token validation for headers

This commit is contained in:
Aelita4 2023-12-29 22:31:29 +01:00
parent 4a34daa54c
commit d3ac213590
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,11 @@ import { getAccessToken } from "../db/accessTokens";
export default async function validateAccessToken(request: Request): Promise<Response | AccessToken> { export default async function validateAccessToken(request: Request): Promise<Response | AccessToken> {
let accessToken = request.url.split("?")[1]?.split("&").filter((x) => x.split("=")[0] === "token")[0].split("=")[1]; let accessToken = request.url.split("?")[1]?.split("&").filter((x) => x.split("=")[0] === "token")[0].split("=")[1];
if(accessToken === undefined) {
const authorization = request.headers.get("Authorization");
if(authorization !== null && authorization.startsWith("Bearer ")) accessToken = authorization.split(" ")[1];
}
const cookies = request.headers.get("Cookie")?.split(";").map((x) => x.trim().split("=")) ?? []; const cookies = request.headers.get("Cookie")?.split(";").map((x) => x.trim().split("=")) ?? [];
if(accessToken === undefined) accessToken = cookies.filter((x) => x[0] === "sessionToken")[0]?.[1]; if(accessToken === undefined) accessToken = cookies.filter((x) => x[0] === "sessionToken")[0]?.[1];