Sign requests for public-keys
rodzic
1219393c29
commit
3e41d98c35
38
index.php
38
index.php
|
@ -170,9 +170,9 @@
|
||||||
"name" => "{$realName}",
|
"name" => "{$realName}",
|
||||||
"summary" => "{$summary}",
|
"summary" => "{$summary}",
|
||||||
"url" => "https://{$server}/{$username}",
|
"url" => "https://{$server}/{$username}",
|
||||||
"manuallyApprovesFollowers" => true,
|
"manuallyApprovesFollowers" => false,
|
||||||
"discoverable" => true,
|
"discoverable" => true,
|
||||||
"published" => "2024-02-29T12:34:00Z",
|
"published" => "2024-02-29T12:34:56Z",
|
||||||
"icon" => [
|
"icon" => [
|
||||||
"type" => "Image",
|
"type" => "Image",
|
||||||
"mediaType" => "image/png",
|
"mediaType" => "image/png",
|
||||||
|
@ -1032,11 +1032,35 @@ HTML;
|
||||||
// This is usually in the form `https://example.com/user/username#main-key`
|
// This is usually in the form `https://example.com/user/username#main-key`
|
||||||
// This is to differentiate if the user has multiple keys
|
// This is to differentiate if the user has multiple keys
|
||||||
// TODO: Check the actual key
|
// TODO: Check the actual key
|
||||||
// This request does not need to be signed. But it does need to specify that it wants a JSON response
|
// This request does not need to be signed normally.
|
||||||
$context = stream_context_create(
|
// Some servers will only respond to signed requests.
|
||||||
[ "http" => [ "header" => "Accept: application/activity+json" ] ]
|
// It need to specify that it wants a JSON response
|
||||||
);
|
|
||||||
$userJSON = file_get_contents( $publicKeyURL, false, $context );
|
$publicKeyURL_host = parse_url( $publicKeyURL, PHP_URL_HOST );
|
||||||
|
$publicKeyURL_path = parse_url( $publicKeyURL, PHP_URL_PATH );
|
||||||
|
|
||||||
|
// Request the JSON representation of the the user
|
||||||
|
$ch = curl_init( $publicKeyURL );
|
||||||
|
|
||||||
|
// Generate signed headers for this request
|
||||||
|
$headers = generate_signed_headers( null, $publicKeyURL_host, $publicKeyURL_path, "GET" );
|
||||||
|
|
||||||
|
// Set cURL options
|
||||||
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
|
||||||
|
|
||||||
|
// Execute the cURL session
|
||||||
|
$userJSON = curl_exec( $ch );
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
// Handle cURL error
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
$userData = json_decode( $userJSON, true );
|
$userData = json_decode( $userJSON, true );
|
||||||
$publicKey = $userData["publicKey"]["publicKeyPem"];
|
$publicKey = $userData["publicKey"]["publicKeyPem"];
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue