possumbot/auth-fetch.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-08-24 12:49:58 +02:00
import express from 'express';
import fs from 'fs';
2024-08-22 17:34:03 +02:00
2024-08-24 12:49:58 +02:00
import env from 'dotenv';
2024-08-22 17:34:03 +02:00
env.config();
const domain = process.env.AP_FETCH_DOMAIN;
2024-08-24 12:49:58 +02:00
const pubkey = fs.readFileSync('data/publickey.crt', 'utf8');
2024-08-22 17:34:03 +02:00
const app = express();
2024-08-24 12:49:58 +02:00
const notice = fs.readFileSync('auth-fetch-notice.txt', 'utf8');
2024-08-22 17:34:03 +02:00
const actor = {
2024-08-24 12:49:58 +02:00
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1'
2024-08-22 17:34:03 +02:00
],
2024-08-24 12:49:58 +02:00
'id': 'https://' + domain + '/actor',
'type': 'Person',
'preferredUsername': 'possumbot',
'inbox': 'https://' + domain + '/inbox',
2024-08-22 17:34:03 +02:00
2024-08-24 12:49:58 +02:00
'publicKey': {
'id': 'https://' + domain + '/actor#main-key',
'owner': 'https://' + domain + '/actor',
'publicKeyPem': pubkey
2024-08-22 17:34:03 +02:00
}
}
const webfinger = {
2024-08-24 12:49:58 +02:00
'subject': 'acct:possumbot@' + domain + '',
2024-08-22 17:34:03 +02:00
2024-08-24 12:49:58 +02:00
'links': [
2024-08-22 17:34:03 +02:00
{
2024-08-24 12:49:58 +02:00
'rel': 'self',
'type': 'application/activity+json',
'href': 'https://' + domain + '/actor'
2024-08-22 17:34:03 +02:00
}
]
}
2024-08-24 12:49:58 +02:00
app.get('/', (req, res) => {
res.setHeader('content-type', 'text/plain');
res.write(notice);
2024-08-22 17:34:03 +02:00
});
2024-08-24 12:49:58 +02:00
app.get('/actor', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/activity+json' });
res.write(JSON.stringify(actor));
res.end();
2024-08-22 17:34:03 +02:00
});
2024-08-24 12:49:58 +02:00
app.get('/.well-known/webfinger', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(webfinger));
res.end();
2024-08-22 17:34:03 +02:00
});
app.listen(process.env.AP_FETCH_PORT);
export default true;