Skip to content

Commit

Permalink
Auth in public links
Browse files Browse the repository at this point in the history
  • Loading branch information
diocas committed Dec 21, 2021
1 parent f29b87c commit 681e0fc
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions packages/web-app-files/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,30 +546,36 @@ export default {
async addAppProviderFile(fileName) {
try {
const parent = this.currentFolder.fileId
const publicToken = (this.$router.currentRoute.params.item || '').split('/')[0]
const configUrl = this.configuration.server
const appNewUrl = this.capabilities.files.app_providers[0].new_url.replace(/^\/+/, '')
const url = configUrl + appNewUrl + `?parent_container_id=${parent}&filename=${fileName}`
const headers = new Headers()
if (!this.isPublicFilesRoute) {
headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')
} else {
headers.append(
'Authorization',
'Basic ' + Buffer.from('public:' + this.publicLinkPassword).toString('base64')
)
const url =
configUrl +
appNewUrl +
`?parent_container_id=${parent}&filename=${encodeURIComponent(fileName)}`
const headers = {
'X-Requested-With': 'XMLHttpRequest',
...(this.isPublicFilesRoute && {
'public-token': publicToken
}),
...(this.publicLinkPassword && {
Authorization:
'Basic ' +
Buffer.from(['public', this.publicLinkPassword].join(':')).toString('base64')
}),
...(this.getToken && {
Authorization: 'Bearer ' + this.getToken
})
}
const response = await fetch(encodeURI(url), {
const response = await fetch(url, {
method: 'POST',
headers
})
await response.json()
if (!response.ok) {
if (response.status !== 200) {
const message = `An error has occured: ${response.status}`
throw new Error(message)
}
Expand Down

0 comments on commit 681e0fc

Please sign in to comment.