refs #1028 Confirm ActivityPub instance to read host-meta before login

This commit is contained in:
AkiraFukushima 2019-09-14 22:22:43 +09:00
parent b2ca839a21
commit dd4ca9432a
1 changed files with 9 additions and 1 deletions

View File

@ -46,9 +46,17 @@ const actions: ActionTree<LoginState, RootState> = {
},
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
await axios.get(`https://${domain}/api/v1/instance`).finally(() => {
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
// Check /.well-known/host-meta to confirm mastodon instance.
const res = await axios.get(`https://${domain}/.well-known/host-meta`).finally(() => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
})
const parser = new DOMParser()
const dom = parser.parseFromString(res.data, 'text/xml')
const link = dom.getElementsByTagName('Link')[0].outerHTML
if (!link.includes(`https://${domain}/.well-known/webfinger`)) {
throw new Error('domain is not activity pub')
}
commit(MUTATION_TYPES.CHANGE_INSTANCE, domain)
return true
}