Merge pull request #1089 from h3poteto/iss-1077

closes #1077 Trim authorization token and domain URL
This commit is contained in:
AkiraFukushima 2019-11-07 23:18:21 +09:00 committed by GitHub
commit f2ccf7dd5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -9,7 +9,7 @@ const state = (): AuthorizeState => ({})
const actions: ActionTree<AuthorizeState, RootState> = {
submit: (_, code: string) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-access-token', code)
ipcRenderer.send('get-access-token', code.trim())
ipcRenderer.once('response-get-access-token', (_, id: string) => {
ipcRenderer.removeAllListeners('error-get-access-token')
resolve(id)

View File

@ -46,13 +46,14 @@ const actions: ActionTree<LoginState, RootState> = {
},
confirmInstance: async ({ commit, rootState }, domain: string): Promise<boolean> => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
const cleanDomain = domain.trim()
try {
await Mastodon.get<Instance>('/api/v1/instance', {}, `https://${domain}`, rootState.App.proxyConfiguration)
await Mastodon.get<Instance>('/api/v1/instance', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration)
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
} catch (err) {
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
// Check /.well-known/host-meta to confirm mastodon instance.
const res = await Mastodon.get<any>('/.well-known/host-meta', {}, `https://${domain}`, rootState.App.proxyConfiguration).finally(
const res = await Mastodon.get<any>('/.well-known/host-meta', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration).finally(
() => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
}
@ -60,11 +61,11 @@ const actions: ActionTree<LoginState, RootState> = {
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`)) {
if (!link.includes(`https://${cleanDomain}/.well-known/webfinger`)) {
throw new Error('domain is not activity pub')
}
}
commit(MUTATION_TYPES.CHANGE_INSTANCE, domain)
commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain)
return true
}
}