♻️ refactor: app token and oAuth endpoint request
These changes include: 1. Replacing the app token with a standard authorization barrier. 2. Changing the response body in the OAuth request by wrapping the endpoint link with a structure instead of placing it in the callback payload data.
This commit is contained in:
@ -3,10 +3,14 @@ import { returnErrorResponse } from "../../helpers/callback/httpResponse";
|
||||
|
||||
export const appAccessTokenMiddleware = () =>
|
||||
new Elysia().onRequest(({ request, set }) => {
|
||||
const headerToken = request.headers.get("access_token");
|
||||
const storedToken = process.env.API_KEY;
|
||||
const headerToken = request.headers.get("authorization");
|
||||
if (!headerToken) return returnErrorResponse(set, 401, "Unauthorized");
|
||||
|
||||
if (headerToken !== storedToken) {
|
||||
return returnErrorResponse(set, 403, "Unauthorized");
|
||||
}
|
||||
const storedToken = process.env.API_KEY;
|
||||
const [scheme, token] = headerToken.split(" ");
|
||||
|
||||
if (scheme !== "Bearer" || !token)
|
||||
return returnErrorResponse(set, 401, "Invalid auth format");
|
||||
if (token !== storedToken)
|
||||
return returnErrorResponse(set, 403, "Forbidden");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user