mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-30 09:04:56 +01:00
refs #1077 Trim authorization token and domain URL
This commit is contained in:
parent
741c58bb0c
commit
03d404d46a
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user