Skip to content

Instantly share code, notes, and snippets.

@pfefferle
Created September 27, 2018 19:13
Show Gist options
  • Save pfefferle/86dea57ed3a1492611a229ea62205179 to your computer and use it in GitHub Desktop.
Save pfefferle/86dea57ed3a1492611a229ea62205179 to your computer and use it in GitHub Desktop.
<?php
// get private key
$key = get_user_meta( 1, 'magic_sig_private_key', true );
$date = gmdate('D, d M Y H:i:s T');
$signed_string = "(request-target): post /inbox\nhost: mastodon.social\ndate: $date";
$signature = null;
openssl_sign( $signed_string, $signature, $key, OPENSSL_ALGO_SHA256 );
$signature = 'keyId="https://pfefferle.org/author/pfefferle/#main-key",algorithm="rsa-sha256",headers="(request-target) host date",signature="' . base64_encode( $signature ) . '"';
$response = wp_safe_remote_post( 'https://mastodon.social/inbox', array(
'headers' => array(
'date' => $date,
'content-type' => 'application/activity+json',
'signature' => $signature,
),
'body' => '{"@context": "https://www.w3.org/ns/activitystreams","id": "https://pfefferle.org/1538041738","type": "Accept","actor": "https://pfefferle.org/author/pfefferle/","object": "https://mastodon.social/users/pfefferle"}',
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment