-
Notifications
You must be signed in to change notification settings - Fork 9
feat(onedrive): implemented secure file download functionality #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(onedrive): implemented secure file download functionality #249
Conversation
- Added direct file download using Graph API and fetch - Implemented progress tracking for downloads - Added fallback mechanism for download URLs - Handled file type and thumbnail preservation - Added proper error handling and user feedback BREAKING CHANGE: Changes the way OneDrive files are downloaded. Uses direct download URLs instead of sharing links
src/hooks/useOneDriveAuth.ts
Outdated
| expiresOn: response.expiresOn!.getTime(), | ||
| } | ||
| setToken(newToken) | ||
| localStorage.setItem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSAL's built-in caching mechanisms are likely a better alternative to localStorage for token management, as they are designed to securely handle tokens and minimize risks like XSS attacks. I'm not sure about the specific case here that led to using localStorage, but if acquireTokenSilent (which I see you've used elsewhere) works in this context, it would definitely be a safer and more reliable approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amjedidiah , just to clarify, I wasn’t suggesting changing the entire cache location setting.
My thought was more about leveraging acquireTokenSilent to fetch the token directly without needing to manually set or retrieve it in localStorage during the flow. That said, I’m not entirely sure if it’s doable, as I haven’t worked with MSAL myself. I trust your judgment and appreciate you looking into it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @BSalaeddin , done
| ) => { | ||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: { Accept: 'application/json' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
downloadFile function sets the Accept header to 'application/json' when fetching file content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @BSalaeddin, done
- removed unnecessary header in src/components/UpupUploader/FileBrowser/BrowserOD.tsx - build fixes
- Removed manual token storage in localStorage in favour of acquireTokenSilent for token management - Fixed logoutPopup type error - Moved `pako` package from devDependencies to dependencies as it should be
| const promises = files.map(async (file, index) => { | ||
| console.log('Processing file:', file) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to clean all the code from console.logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MedAmine1212 , done
|
|
||
| console.log('Got download URL:', downloadUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove console.log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MedAmine1212 , done

BREAKING CHANGE: Changes the way OneDrive files are downloaded. Uses direct download URLs instead of sharing links
Demo.mp4