forked from Mirrors/keyoxide-web
Support twitter proof
This commit is contained in:
parent
da93579ca0
commit
3421695d72
2 changed files with 55 additions and 1 deletions
|
@ -245,7 +245,7 @@ async function displayProfile(opts) {
|
|||
|
||||
async function verifyProof(url, fingerprint) {
|
||||
// Init
|
||||
let reVerify, output = {url: url, type: null, proofUrl: url, proofUrlFetch: null, isVerified: false, display: null};
|
||||
let reVerify, match, output = {url: url, type: null, proofUrl: url, proofUrlFetch: null, isVerified: false, display: null};
|
||||
|
||||
// DNS
|
||||
if (/^dns:/.test(url)) {
|
||||
|
@ -277,6 +277,30 @@ async function verifyProof(url, fingerprint) {
|
|||
return output;
|
||||
}
|
||||
}
|
||||
// Twitter
|
||||
if (/^https:\/\/twitter.com/.test(url)) {
|
||||
output.type = "twitter";
|
||||
match = url.match(/https:\/\/twitter\.com\/(.*)\/status\/(.*)/);
|
||||
output.display = `@${match[1]}`;
|
||||
output.url = `https://twitter.com/${match[1]}`;
|
||||
output.proofUrlFetch = `/server/verifyTweet.php?id=${match[2]}&fp=${fingerprint}`;
|
||||
try {
|
||||
response = await fetch(output.proofUrlFetch, {
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
},
|
||||
credentials: 'omit'
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Response failed: ' + response.status);
|
||||
}
|
||||
json = await response.json();
|
||||
output.isVerified = json.verified;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
// HN
|
||||
if (/^https:\/\/news.ycombinator.com/.test(url)) {
|
||||
output.type = "hn";
|
||||
|
|
30
server/verifyTweet.php
Normal file
30
server/verifyTweet.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
include 'secrets.php';
|
||||
|
||||
$fingerprint = htmlspecialchars($_GET["fp"]);
|
||||
$tweetId = htmlspecialchars($_GET["id"]);
|
||||
|
||||
$check = "\[Verifying my OpenPGP key: openpgp4fpr:$fingerprint\]";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $twitter_api_auth));
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, "https://api.twitter.com/labs/2/tweets/$tweetId?tweet.fields=author_id,created_at,id,source,text");
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
$response = array();
|
||||
$response["fingerprint"] = false;
|
||||
$response["fingerprint"] = $fingerprint;
|
||||
$response["tweetId"] = $tweetId;
|
||||
$response["text"] = $data["data"]["text"];
|
||||
|
||||
if (preg_match("/{$check}/i", $data["data"]["text"])) {
|
||||
$response["verified"] = true;
|
||||
}
|
||||
echo json_encode($response);
|
||||
|
||||
?>
|
Loading…
Reference in a new issue