mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-07 20:44:46 +02:00
Fix host path extra port, fix formatting
This commit is contained in:
parent
8b631f7860
commit
d613d8954d
1 changed files with 18 additions and 22 deletions
|
@ -78,14 +78,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { App } from '@capacitor/app';
|
import { App } from '@capacitor/app'
|
||||||
import { Browser } from '@capacitor/browser';
|
import { Browser } from '@capacitor/browser'
|
||||||
import { Capacitor } from '@capacitor/core';
|
import { Capacitor } from '@capacitor/core'
|
||||||
import { CapacitorHttp } from '@capacitor/core'
|
import { CapacitorHttp } from '@capacitor/core'
|
||||||
import { Dialog } from '@capacitor/dialog'
|
import { Dialog } from '@capacitor/dialog'
|
||||||
|
|
||||||
// Variable which is set to an instance of ServerConnectForm.vue used below of the listener
|
// Variable which is set to an instance of ServerConnectForm.vue used below of the listener
|
||||||
let serverConnectForm = null;
|
let serverConnectForm = null
|
||||||
|
|
||||||
App.addListener('appUrlOpen', async (data) => {
|
App.addListener('appUrlOpen', async (data) => {
|
||||||
// Handle the OAuth callback
|
// Handle the OAuth callback
|
||||||
|
@ -105,7 +105,7 @@ App.addListener('appUrlOpen', async (data) => {
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[appUrlOpen] Unknown url: ${data.url} - host: ${url.hostname} - path: ${url.pathname}`)
|
console.warn(`[appUrlOpen] Unknown url: ${data.url} - host: ${url.hostname} - path: ${url.pathname}`)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
@ -178,19 +178,17 @@ export default {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = `${redirectUrl.protocol}//${redirectUrl.host}${redirectUrl.port ? ':' + redirectUrl.port : ''}`
|
const host = `${redirectUrl.protocol}//${redirectUrl.host}`
|
||||||
const buildUrl = `${host}${redirectUrl.pathname}?response_type=code` +
|
const buildUrl = `${host}${redirectUrl.pathname}?response_type=code` + `&client_id=${encodeURIComponent(client_id)}&scope=${encodeURIComponent(scope)}&state=${encodeURIComponent(state)}` + `&redirect_uri=${encodeURIComponent('audiobookshelf://oauth')}`
|
||||||
`&client_id=${encodeURIComponent(client_id)}&scope=${encodeURIComponent(scope)}&state=${encodeURIComponent(state)}` +
|
|
||||||
`&redirect_uri=${encodeURIComponent('audiobookshelf://oauth')}`
|
|
||||||
|
|
||||||
// example url for authentik
|
// example url for authentik
|
||||||
// const authURL = "https://authentik/application/o/authorize/?response_type=code&client_id=41cd96f...&redirect_uri=audiobookshelf%3A%2F%2Foauth&scope=openid%20openid%20email%20profile&state=asdds...";
|
// const authURL = "https://authentik/application/o/authorize/?response_type=code&client_id=41cd96f...&redirect_uri=audiobookshelf%3A%2F%2Foauth&scope=openid%20openid%20email%20profile&state=asdds..."
|
||||||
|
|
||||||
// Open the browser. The browser/identity provider in turn will redirect to an in-app link supplementing a code
|
// Open the browser. The browser/identity provider in turn will redirect to an in-app link supplementing a code
|
||||||
try {
|
try {
|
||||||
await Browser.open({ url: buildUrl });
|
await Browser.open({ url: buildUrl })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error opening browser", error);
|
console.error('Error opening browser', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async oauthRequest(url) {
|
async oauthRequest(url) {
|
||||||
|
@ -203,12 +201,12 @@ export default {
|
||||||
url: backendEndpoint,
|
url: backendEndpoint,
|
||||||
disableRedirects: true,
|
disableRedirects: true,
|
||||||
webFetchExtra: {
|
webFetchExtra: {
|
||||||
redirect: "manual"
|
redirect: 'manual'
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Depending on iOS or Android, it can be location or Location...
|
// Depending on iOS or Android, it can be location or Location...
|
||||||
const locationHeader = response.headers[Object.keys(response.headers).find(key => key.toLowerCase() === 'location')];
|
const locationHeader = response.headers[Object.keys(response.headers).find((key) => key.toLowerCase() === 'location')]
|
||||||
if (locationHeader) {
|
if (locationHeader) {
|
||||||
const url = new URL(locationHeader)
|
const url = new URL(locationHeader)
|
||||||
return url
|
return url
|
||||||
|
@ -217,7 +215,6 @@ export default {
|
||||||
this.$toast.error(`SSO: Invalid answer`)
|
this.$toast.error(`SSO: Invalid answer`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('[SSO] Error in oauthRequest: ' + error)
|
console.log('[SSO] Error in oauthRequest: ' + error)
|
||||||
this.$toast.error(`SSO error: ${error}`)
|
this.$toast.error(`SSO error: ${error}`)
|
||||||
|
@ -226,7 +223,7 @@ export default {
|
||||||
},
|
},
|
||||||
async oauthExchangeCodeForToken(code, state) {
|
async oauthExchangeCodeForToken(code, state) {
|
||||||
// We need to read the url directly from this.serverConfig.address as the callback which is called via the external browser does not pass us that info
|
// We need to read the url directly from this.serverConfig.address as the callback which is called via the external browser does not pass us that info
|
||||||
const backendEndpoint = `${this.serverConfig.address}/auth/openid/callback?state=${encodeURIComponent(state)}&code=${encodeURIComponent(code)}`;
|
const backendEndpoint = `${this.serverConfig.address}/auth/openid/callback?state=${encodeURIComponent(state)}&code=${encodeURIComponent(code)}`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// We can close the browser at this point (does not work on Android)
|
// We can close the browser at this point (does not work on Android)
|
||||||
|
@ -236,24 +233,23 @@ export default {
|
||||||
|
|
||||||
const response = await CapacitorHttp.get({
|
const response = await CapacitorHttp.get({
|
||||||
url: backendEndpoint
|
url: backendEndpoint
|
||||||
});
|
})
|
||||||
|
|
||||||
serverConnectForm.serverConfig.token = response.data.user.token
|
serverConnectForm.serverConfig.token = response.data.user.token
|
||||||
const payload = await serverConnectForm.authenticateToken()
|
const payload = await serverConnectForm.authenticateToken()
|
||||||
|
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
console.log('[SSO] Failed getting token: ' + this.error);
|
console.log('[SSO] Failed getting token: ' + this.error)
|
||||||
this.$toast.error(`SSO error: ${this.error}`)
|
this.$toast.error(`SSO error: ${this.error}`)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
serverConnectForm.setUserAndConnection(payload)
|
serverConnectForm.setUserAndConnection(payload)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('[SSO] Error in exchangeCodeForToken: ' + error);
|
console.log('[SSO] Error in exchangeCodeForToken: ' + error)
|
||||||
this.$toast.error(`SSO error: ${error}`)
|
this.$toast.error(`SSO error: ${error}`)
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addCustomHeaders() {
|
addCustomHeaders() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue