Forward Auth refactor and adding PROXY_FORWARD_AUTH_LOGOUT_URI env

This commit is contained in:
advplyr 2022-12-18 11:37:45 -06:00
parent 8558baf30a
commit 73a61872fa
9 changed files with 139 additions and 68 deletions

View file

@ -75,9 +75,8 @@ export default {
this.$setLanguageCode(lang)
},
logout() {
var rootSocket = this.$root.socket || {}
const logoutPayload = {
socketId: rootSocket.id
socketId: (this.$root.socket || {}).id
}
this.$axios.$post('/logout', logoutPayload).catch((error) => {
console.error(error)
@ -87,7 +86,13 @@ export default {
}
this.$store.commit('libraries/setUserPlaylists', [])
this.$store.commit('libraries/setCollections', [])
this.$router.push('/login')
if (this.$store.getters['user/getForwardAuthLogoutURI']) {
// Redirect to forward auth logout uri
location.replace(this.$store.getters['user/getForwardAuthLogoutURI'])
} else {
this.$router.push('/login')
}
},
resetForm() {
this.password = null

View file

@ -144,20 +144,20 @@ export default {
* Checks for forward proxy authentication
*/
async checkForwardAuth() {
this.processing = true;
this.error = null;
this.processing = true
this.error = null
var authRes = await this.$axios.$post('/forwardauth').catch((error) => {
console.error('Failed', error.response)
if (error.response) this.error = error.response.data
else this.error = 'Unknown Error'
return false
});
})
if (authRes && authRes.disabled) {
// disabled == true - proxy auth has not been configured on the server, nothing further to do.
this.processing = false;
return false;
this.processing = false
return false
}
if (authRes && authRes.error) {
@ -166,17 +166,16 @@ export default {
this.setUser(authRes)
}
this.processing = false
},
async submitForm() {
this.error = null
this.processing = true
var payload = {
const payload = {
username: this.username,
password: this.password || ''
}
var authRes = await this.$axios.$post('/login', payload).catch((error) => {
const authRes = await this.$axios.$post('/login', payload).catch((error) => {
console.error('Failed', error.response)
if (error.response) this.error = error.response.data
else this.error = 'Unknown Error'
@ -190,7 +189,7 @@ export default {
this.processing = false
},
checkAuth() {
var token = localStorage.getItem('token')
const token = localStorage.getItem('token')
if (!token) return false
this.processing = true
@ -203,43 +202,44 @@ export default {
})
.then((res) => {
this.setUser(res)
this.processing = false
return true
})
.catch((error) => {
console.error('Authorize error', error)
this.processing = false
return false
})
.finally(() => {
this.processing = false
})
},
checkStatus() {
this.processing = true
this.$axios
.$get('/status')
.then((res) => {
this.processing = false
this.isInit = res.isInit
this.showInitScreen = !res.isInit
this.$setServerLanguageCode(res.language)
if (this.showInitScreen) {
this.ConfigPath = res.ConfigPath || ''
this.MetadataPath = res.MetadataPath || ''
} else if (res.forwardAuthUserResponse) {
// User was returned from forward auth
this.setUser(res.forwardAuthUserResponse)
}
})
.catch((error) => {
console.error('Status check failed', error)
this.processing = false
this.criticalError = 'Status check failed'
})
.finally(() => {
this.processing = false
})
}
},
async mounted() {
// Check for proxy auth
this.checkForwardAuth();
if (localStorage.getItem('token')) {
var userfound = await this.checkAuth()
const userfound = await this.checkAuth()
if (userfound) return // if valid user no need to check status
}
this.checkStatus()