mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-22 09:19:19 +02:00
Send Accept to the private inbox of the user
This commit is contained in:
parent
609c640fc4
commit
48d1a7ba87
|
@ -6,6 +6,9 @@ const express = require('express'),
|
|||
router = express.Router();
|
||||
|
||||
function signAndSend(message, name, domain, req, res, targetDomain) {
|
||||
// get the URI of the actor object and append 'inbox' to it
|
||||
let inbox = message.object.actor+'/inbox';
|
||||
let inboxFragment = inbox.replace('https://'+targetDomain,'');
|
||||
// get the private key
|
||||
let db = req.app.get('db');
|
||||
let result = db.prepare('select privkey from accounts where name = ?').get(`${name}@${domain}`);
|
||||
|
@ -16,15 +19,16 @@ function signAndSend(message, name, domain, req, res, targetDomain) {
|
|||
let privkey = result.privkey;
|
||||
const signer = crypto.createSign('sha256');
|
||||
let d = new Date();
|
||||
let stringToSign = `(request-target): post /inbox\nhost: ${targetDomain}\ndate: ${d.toUTCString()}`;
|
||||
let stringToSign = `(request-target): post ${inboxFragment}\nhost: ${targetDomain}\ndate: ${d.toUTCString()}`;
|
||||
signer.update(stringToSign);
|
||||
signer.end();
|
||||
const signature = signer.sign(privkey);
|
||||
const signature_b64 = signature.toString('base64');
|
||||
let header = `keyId="https://${domain}/u/${name}",headers="(request-target) host date",signature="${signature_b64}"`;
|
||||
console.log('signature:',header);
|
||||
console.log('message:',message);
|
||||
request({
|
||||
url: `https://${targetDomain}/inbox`,
|
||||
url: inbox,
|
||||
headers: {
|
||||
'Host': targetDomain,
|
||||
'Date': d.toUTCString(),
|
||||
|
|
Loading…
Reference in New Issue