Add new API endpoint (accounts/verify_credentials)

This commit is contained in:
Jesse Wierzbinski 2023-09-21 16:15:12 -10:00
parent e25b745e25
commit ce2ed0754e
11 changed files with 234 additions and 181 deletions

View file

@ -89,7 +89,7 @@ export default async (
Hashtag: "as:Hashtag",
},
],
id: `${config.http.base_url}:${config.http.port}/@${user.username}`,
id: `${config.http.base_url}/@${user.username}`,
type: "Person",
preferredUsername: user.username, // TODO: Add user display name
name: user.username,
@ -104,21 +104,21 @@ export default async (
url: user.header,
mediaType: "image/png", // TODO: Set user header mimetype
},
inbox: `${config.http.base_url}:${config.http.port}/@${user.username}/inbox`,
outbox: `${config.http.base_url}:${config.http.port}/@${user.username}/outbox`,
followers: `${config.http.base_url}:${config.http.port}/@${user.username}/followers`,
following: `${config.http.base_url}:${config.http.port}/@${user.username}/following`,
liked: `${config.http.base_url}:${config.http.port}/@${user.username}/liked`,
inbox: `${config.http.base_url}/@${user.username}/inbox`,
outbox: `${config.http.base_url}/@${user.username}/outbox`,
followers: `${config.http.base_url}/@${user.username}/followers`,
following: `${config.http.base_url}/@${user.username}/following`,
liked: `${config.http.base_url}/@${user.username}/liked`,
discoverable: true,
alsoKnownAs: [
// TODO: Add accounts from which the user migrated
],
manuallyApprovesFollowers: false, // TODO: Change
publicKey: {
id: `${getHost()}${config.http.base_url}:${config.http.port}/@${
id: `${getHost()}${config.http.base_url}/@${
user.username
}/actor#main-key`,
owner: `${config.http.base_url}:${config.http.port}/@${user.username}`,
owner: `${config.http.base_url}/@${user.username}`,
// Split the public key into PEM format
publicKeyPem: `-----BEGIN PUBLIC KEY-----\n${user.public_key
.match(/.{1,64}/g)
@ -131,7 +131,7 @@ export default async (
// TODO: Add user attachments (I.E. profile metadata)
],
endpoints: {
sharedInbox: `${config.http.base_url}:${config.http.port}/inbox`,
sharedInbox: `${config.http.base_url}/inbox`,
},
});
};

View file

@ -0,0 +1,35 @@
import { getUserByToken } from "@auth";
import { errorResponse, jsonResponse } from "@response";
/**
* Patches a user
*/
export default async (req: Request): Promise<Response> => {
// Check if request is a PATCH request
if (req.method !== "GET")
return errorResponse("This method requires a GET request", 405);
// 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);
if (!user) return errorResponse("Unauthorized", 401);
// TODO: Add Source fields
return jsonResponse({
...(await user.toAPI()),
source: user.source,
// TODO: Add role support
role: {
id: 0,
name: "",
permissions: "",
color: "",
highlighted: false,
},
});
};