mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2025-01-09 14:29:27 -07:00
Add Twitter proxy verification
This commit is contained in:
parent
c9439a40b1
commit
cee8fa9172
1 changed files with 39 additions and 15 deletions
|
@ -16,10 +16,14 @@ limitations under the License.
|
||||||
const bent = require('bent')
|
const bent = require('bent')
|
||||||
const req = bent('GET')
|
const req = bent('GET')
|
||||||
const serviceproviders = require('../serviceproviders')
|
const serviceproviders = require('../serviceproviders')
|
||||||
|
const utils = require('../utils')
|
||||||
const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/
|
const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/
|
||||||
|
|
||||||
const customRequestHandler = async (spData, opts) => {
|
const customRequestHandler = async (spData, opts) => {
|
||||||
const match = spData.proof.uri.match(reURI)
|
const match = spData.proof.uri.match(reURI)
|
||||||
|
|
||||||
|
// Attempt direct verification if policy allows it
|
||||||
|
if (opts.proxyPolicy !== 'always') {
|
||||||
if ('twitterBearerToken' in opts && opts.twitterBearerToken) {
|
if ('twitterBearerToken' in opts && opts.twitterBearerToken) {
|
||||||
const res = await req(`https://api.twitter.com/1.1/statuses/show.json?id=${match[2]}`, null, {
|
const res = await req(`https://api.twitter.com/1.1/statuses/show.json?id=${match[2]}`, null, {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
|
@ -36,6 +40,26 @@ const customRequestHandler = async (spData, opts) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt proxy verification if policy allows it
|
||||||
|
if (opts.proxyPolicy !== 'never' && spData.proof.fetch) {
|
||||||
|
return req(utils.generateProxyURL('twitter', match[2], opts), null, {
|
||||||
|
Accept: 'application/json',
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
return await res.json()
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
return res.data.text
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
reject(e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// No verification
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const processURI = (uri, opts) => {
|
const processURI = (uri, opts) => {
|
||||||
if (!opts) {
|
if (!opts) {
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -54,8 +78,8 @@ const processURI = (uri, opts) => {
|
||||||
},
|
},
|
||||||
proof: {
|
proof: {
|
||||||
uri: uri,
|
uri: uri,
|
||||||
fetch: null,
|
fetch: utils.generateProxyURL('twitter', match[2], opts),
|
||||||
useProxy: true,
|
useProxy: false,
|
||||||
format: 'text',
|
format: 'text',
|
||||||
},
|
},
|
||||||
claim: {
|
claim: {
|
||||||
|
|
Loading…
Reference in a new issue