mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Add new endpoint - verify_credentials
This commit is contained in:
parent
756be54e6f
commit
f5640966c7
4 changed files with 58 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
28
server/api/api/v1/apps/verify_credentials/index.ts
Normal file
28
server/api/api/v1/apps/verify_credentials/index.ts
Normal 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,
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue