aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webfinger.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-09 17:51:58 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite4f97babf701481b55cc10fb3448feab5f97c867 (patch)
treeaf37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/helpers/webfinger.ts
parent343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff)
downloadPeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip
Begin activitypub
Diffstat (limited to 'server/helpers/webfinger.ts')
-rw-r--r--server/helpers/webfinger.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
new file mode 100644
index 000000000..9586fa562
--- /dev/null
+++ b/server/helpers/webfinger.ts
@@ -0,0 +1,44 @@
1import * as WebFinger from 'webfinger.js'
2
3import { isTestInstance } from './core-utils'
4import { isActivityPubUrlValid } from './custom-validators'
5import { WebFingerData } from '../../shared'
6import { fetchRemoteAccountAndCreatePod } from './activitypub'
7
8const webfinger = new WebFinger({
9 webfist_fallback: false,
10 tls_only: isTestInstance(),
11 uri_fallback: false,
12 request_timeout: 3000
13})
14
15async function getAccountFromWebfinger (url: string) {
16 const webfingerData: WebFingerData = await webfingerLookup(url)
17
18 if (Array.isArray(webfingerData.links) === false) return undefined
19
20 const selfLink = webfingerData.links.find(l => l.rel === 'self')
21 if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined
22
23 const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href)
24
25 return account
26}
27
28// ---------------------------------------------------------------------------
29
30export {
31 getAccountFromWebfinger
32}
33
34// ---------------------------------------------------------------------------
35
36function webfingerLookup (url: string) {
37 return new Promise<WebFingerData>((res, rej) => {
38 webfinger.lookup('nick@silverbucket.net', (err, p) => {
39 if (err) return rej(err)
40
41 return p
42 })
43 })
44}