mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Use request handlers
This commit is contained in:
parent
bb58fc3614
commit
8d44b4f9bc
2 changed files with 31 additions and 16 deletions
22
src/index.js
22
src/index.js
|
@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
const validUrl = require('valid-url')
|
||||
const bent = require('bent')
|
||||
const req = bent('GET')
|
||||
const serviceproviders = require('./serviceproviders')
|
||||
const claimVerification = require('./claimVerification')
|
||||
const utils = require('./utils')
|
||||
|
@ -41,20 +39,12 @@ const verify = async (uri, fingerprint, opts) => {
|
|||
|
||||
res = null
|
||||
|
||||
if (!spData.proof.useProxy || 'useProxyWhenNeeded' in opts && !opts.useProxyWhenNeeded) {
|
||||
res = await req(spData.proof.fetch ? spData.proof.fetch : spData.proof.uri)
|
||||
|
||||
switch (spData.proof.format) {
|
||||
case 'json':
|
||||
proofData = await res.json()
|
||||
break
|
||||
case 'text':
|
||||
proofData = await res.text()
|
||||
break
|
||||
default:
|
||||
throw new Error('No specified proof data format')
|
||||
break
|
||||
}
|
||||
if (spData.customRequestHandler instanceof Function) {
|
||||
proofData = spData.customRequestHandler(spData, opts)
|
||||
} else if (!spData.proof.useProxy || 'useProxyWhenNeeded' in opts && !opts.useProxyWhenNeeded) {
|
||||
proofData = serviceproviders.directRequestHandler(spData)
|
||||
} else {
|
||||
proofData = serviceproviders.proxyRequestHandler(spData)
|
||||
}
|
||||
|
||||
claimHasBeenVerified = claimVerification.run(proofData, spData)
|
||||
|
|
|
@ -13,6 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const bent = require('bent')
|
||||
const req = bent('GET')
|
||||
|
||||
const list = [
|
||||
'dns',
|
||||
'xmpp',
|
||||
|
@ -50,6 +53,28 @@ const match = (uri, opts) => {
|
|||
return matches
|
||||
}
|
||||
|
||||
const directRequestHandler = (spData) => {
|
||||
const res = await req(spData.proof.fetch ? spData.proof.fetch : spData.proof.uri)
|
||||
|
||||
switch (spData.proof.format) {
|
||||
case 'json':
|
||||
return await res.json()
|
||||
break
|
||||
case 'text':
|
||||
return await res.text()
|
||||
break
|
||||
default:
|
||||
throw new Error('No specified proof data format')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const proxyRequestHandler = (spData) => {
|
||||
return null
|
||||
}
|
||||
|
||||
exports.list = list
|
||||
exports.data = data
|
||||
exports.match = match
|
||||
exports.directRequestHandler = directRequestHandler
|
||||
exports.proxyRequestHandler = proxyRequestHandler
|
||||
|
|
Loading…
Reference in a new issue