diff --git a/changelog/unreleased/bugfix-token-renewal-during-upload b/changelog/unreleased/bugfix-token-renewal-during-upload new file mode 100644 index 00000000000..b96ef0466fe --- /dev/null +++ b/changelog/unreleased/bugfix-token-renewal-during-upload @@ -0,0 +1,6 @@ +Bugfix: Access token renewal during upload + +We've fixed the access token renewal during ongoing uploads. + +https://github.com/owncloud/web/issues/7240 +https://github.com/owncloud/web/pull/7296 diff --git a/packages/web-runtime/src/composables/upload/useUpload.ts b/packages/web-runtime/src/composables/upload/useUpload.ts index 62ef6672fd8..3805dc1273e 100644 --- a/packages/web-runtime/src/composables/upload/useUpload.ts +++ b/packages/web-runtime/src/composables/upload/useUpload.ts @@ -76,7 +76,10 @@ export function useUpload(options: UploadOptions): UploadResult { return { isTusSupported, - headers: unref(headers), + onBeforeRequest: (req) => { + req.setHeader('Authorization', unref(headers).Authorization) + }, + headers: () => unref(headers), ...(isTusSupported && { tusMaxChunkSize: unref(tusMaxChunkSize), tusHttpMethodOverride: unref(tusHttpMethodOverride), diff --git a/packages/web-runtime/src/services/uppyService.ts b/packages/web-runtime/src/services/uppyService.ts index 35ab45b58e1..76037cf83e5 100644 --- a/packages/web-runtime/src/services/uppyService.ts +++ b/packages/web-runtime/src/services/uppyService.ts @@ -33,24 +33,24 @@ export class UppyService { tusMaxChunkSize, tusHttpMethodOverride, tusExtension, - headers + onBeforeRequest }: { tusMaxChunkSize: number tusHttpMethodOverride: boolean tusExtension: string - headers: { [key: string]: string } + onBeforeRequest: () => void }) { const chunkSize = tusMaxChunkSize || Infinity const uploadDataDuringCreation = tusExtension.includes('creation-with-upload') const tusPluginOptions = { - headers: headers, chunkSize: chunkSize, removeFingerprintOnSuccess: true, overridePatchMethod: !!tusHttpMethodOverride, retryDelays: [0, 500, 1000], // @TODO Use uploadDataDuringCreation once https://github.com/tus/tus-js-client/issues/397 is solved - uploadDataDuringCreation: false + uploadDataDuringCreation: false, + onBeforeRequest } const xhrPlugin = this.uppy.getPlugin('XHRUpload') @@ -64,10 +64,16 @@ export class UppyService { return } - this.uppy.use(CustomTus, tusPluginOptions as TusOptions) + this.uppy.use(CustomTus, tusPluginOptions as unknown as TusOptions) } - useXhr({ headers }: { headers: { [key: string]: string } }) { + useXhr({ + headers + }: { + headers: () => { + [name: string]: string | number + } + }) { const xhrPluginOptions: XHRUploadOptions = { endpoint: '', method: 'put',