diff --git a/src/components/MastodonForm.vue b/src/components/MastodonForm.vue index ad011a8d6b071fa31f37ba3742a439d4a694500f..67c4019c7e31a6161524f0a566cc03035315d777 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 5487d0f40c1472dc8f308c9f91b908b54d45049c..f0c42695c9e4138c9a34b73900d313935959189b 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)