From 603e5a0f35a9d77e42368f5d18df2b2f2d5f12e6 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 6 Jul 2020 11:44:36 +0200 Subject: [PATCH] Add discourse identity proof --- CHANGELOG.md | 2 ++ assets/scripts.js | 34 +++++++++++++++++++++++++++++++--- server/verifyDiscourse.php | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 server/verifyDiscourse.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df83c2..bcf80a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added discourse identity proof ## [0.1.0] - 2020-07-05 ### Added diff --git a/assets/scripts.js b/assets/scripts.js index 5339c92..ec363e1 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -514,6 +514,7 @@ async function verifyProof(url, fingerprint) { output.display = `${match[1]}@${match[2]}`; } // Catchall + // Mastodon try { response = await fetch(url, { headers: { @@ -526,7 +527,6 @@ async function verifyProof(url, fingerprint) { } json = await response.json(); if ('attachment' in json) { - // Potentially Mastodon match = url.match(/https:\/\/(.*)\/@(.*)/); json.attachment.forEach((item, i) => { if (item.value.toUpperCase() === fingerprint.toUpperCase()) { @@ -537,10 +537,38 @@ async function verifyProof(url, fingerprint) { } }); } - } catch (e) { - } finally { return output; + } catch (e) { + console.warn(e); } + // Discourse + try { + match = url.match(/https:\/\/(.*)\/u\/(.*)/); + output.proofUrlFetch = `/server/verifyDiscourse.php?url=${url}&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(); + if (json.isDiscourse) { + output.type = "discourse"; + output.display = `${json.user}@${match[1]}`; + output.isVerified = json.verified; + return output; + } + } catch (e) { + console.warn(e); + } + } catch (e) { + console.warn(e); + } + return output; } async function fetchKeys(opts) { diff --git a/server/verifyDiscourse.php b/server/verifyDiscourse.php new file mode 100644 index 0000000..242ad91 --- /dev/null +++ b/server/verifyDiscourse.php @@ -0,0 +1,33 @@ +