Add new endpoint - verify_credentials

This commit is contained in:
Jesse Wierzbinski 2023-09-21 15:41:12 -10:00
parent 756be54e6f
commit f5640966c7
4 changed files with 58 additions and 1 deletions

View file

@ -68,7 +68,6 @@ export default async (
const activity = await RawActivity.addIfNotExists(body, object);
if (activity instanceof Response) {
console.log(await activity.text());
return activity;
}

View file

@ -0,0 +1,28 @@
import { getUserByToken } from "@auth";
import { errorResponse, jsonResponse } from "@response";
import { Application } from "~database/entities/Application";
/**
* Returns OAuth2 credentials
*/
export default async (req: Request): Promise<Response> => {
// Check auth token
const token = req.headers.get("Authorization")?.split(" ")[1] || null;
if (!token)
return errorResponse("This method requires an authenticated user", 422);
const user = await getUserByToken(token);
const application = await Application.getFromToken(token);
if (!user) return errorResponse("Unauthorized", 401);
if (!application) return errorResponse("Unauthorized", 401);
return jsonResponse({
name: application.name,
website: application.website,
vapid_key: application.vapid_key,
redirect_uris: application.redirect_uris,
scopes: application.scopes,
});
};