Verified Commit 60ffdb3e authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fixed support for Pleroma

parent ab8f00e1
Pipeline #4291 passed with stages
in 1 minute and 33 seconds
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment