From 60ffdb3e633996b111106e09441a121ecb9258b4 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Tue, 11 Jun 2019 16:31:36 +0200 Subject: [PATCH] Fixed support for Pleroma --- src/components/MastodonForm.vue | 16 ++++++++++++++-- src/sources/mastodon.js | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/MastodonForm.vue b/src/components/MastodonForm.vue index ad011a8..67c4019 100644 --- a/src/components/MastodonForm.vue +++ b/src/components/MastodonForm.vue @@ -36,11 +36,23 @@ export default { baseURL: instanceUrl, timeout: 3000, }) - let response = await createApp(ax, {baseUrl}) + // we check wether the server is running pleroma or not, because + // pleroma support lets scopes than Mastodon + let scopes + let instanceResponse = await ax.get('/api/v1/instance') + let version = instanceResponse.data.version || '' + if (version.toLowerCase().indexOf('(compatible; pleroma ')) { + console.log('Pleroma detected, asking for "read" scope only!') + scopes = 'read' + } else { + console.log('Mastodon detected, using standard scopes') + scopes = SCOPES + } + let response = await createApp(ax, {baseUrl, scopes}) const appData = response.data const redirectUri = encodeURIComponent(`${baseUrl}/connect/mastodon/callback`) this.$store.commit('setRecursiveState', {key: "sources.mastodon.appCredentials", suffix: this.domain, value: appData}) - let params = `response_type=code&scope=${encodeURIComponent(SCOPES)}&redirect_uri=${redirectUri}&state=${this.domain}&client_id=${appData.client_id}` + let params = `response_type=code&scope=${encodeURIComponent(scopes)}&redirect_uri=${redirectUri}&state=${this.domain}&client_id=${appData.client_id}` const authorizeUrl = `${instanceUrl}oauth/authorize?${params}` console.log('Redirecting user...', authorizeUrl) window.location = authorizeUrl diff --git a/src/sources/mastodon.js b/src/sources/mastodon.js index 5487d0f..f0c4269 100644 --- a/src/sources/mastodon.js +++ b/src/sources/mastodon.js @@ -26,11 +26,11 @@ export function getAxios(url) { } -export async function createApp(ax, {baseUrl}) { +export async function createApp(ax, {baseUrl, scopes}) { const payload = { client_name: `Retribute ${window.location.hostname}`, website: baseUrl, - scopes: SCOPES, + scopes, redirect_uris: `${baseUrl}/connect/mastodon/callback` } const response = await ax.post('/api/v1/apps', payload) -- GitLab