1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-01-30 17:15:16 +01:00

refs #1077 Trim authorization token and domain URL

This commit is contained in:
AkiraFukushima 2019-11-07 23:16:09 +09:00
parent 741c58bb0c
commit 03d404d46a
2 changed files with 6 additions and 5 deletions

View File

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

View File

@ -46,13 +46,14 @@ const actions: ActionTree<LoginState, RootState> = {
}, },
confirmInstance: async ({ commit, rootState }, domain: string): Promise<boolean> => { confirmInstance: async ({ commit, rootState }, domain: string): Promise<boolean> => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, true) commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
const cleanDomain = domain.trim()
try { 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) commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
} catch (err) { } catch (err) {
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8 // https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
// Check /.well-known/host-meta to confirm mastodon instance. // 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) commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
} }
@ -60,11 +61,11 @@ const actions: ActionTree<LoginState, RootState> = {
const parser = new DOMParser() const parser = new DOMParser()
const dom = parser.parseFromString(res.data, 'text/xml') const dom = parser.parseFromString(res.data, 'text/xml')
const link = dom.getElementsByTagName('Link')[0].outerHTML 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') throw new Error('domain is not activity pub')
} }
} }
commit(MUTATION_TYPES.CHANGE_INSTANCE, domain) commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain)
return true return true
} }
} }