Skip to content

Conversation

@amjedidiah
Copy link
Contributor

@amjedidiah amjedidiah commented Nov 7, 2024

  • 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

Demo.mp4

- 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
@amjedidiah amjedidiah changed the title feat(onedrive): implemented secure file download functionality [WIP] feat(onedrive): implemented secure file download functionality Nov 7, 2024
@amjedidiah amjedidiah changed the title [WIP] feat(onedrive): implemented secure file download functionality feat(onedrive): implemented secure file download functionality Nov 11, 2024
expiresOn: response.expiresOn!.getTime(),
}
setToken(newToken)
localStorage.setItem(
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BSalaeddin

Not sure if we can do without either localStorage or sessionStorage
However, I will look this up.

Screenshot 2024-11-22 at 23 18 20

Copy link
Collaborator

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!

Copy link
Contributor Author

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' },
Copy link
Collaborator

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

Copy link
Contributor Author

@amjedidiah amjedidiah Nov 22, 2024

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
@amjedidiah amjedidiah changed the title feat(onedrive): implemented secure file download functionality [pending review changes] feat(onedrive): implemented secure file download functionality Nov 22, 2024
- 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
@amjedidiah amjedidiah changed the title [pending review changes] feat(onedrive): implemented secure file download functionality feat(onedrive): implemented secure file download functionality Nov 26, 2024
@MedAmine1212 MedAmine1212 self-requested a review November 26, 2024 19:48
Comment on lines 178 to 180
const promises = files.map(async (file, index) => {
console.log('Processing file:', file)

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MedAmine1212 , done

Comment on lines 186 to 187

console.log('Got download URL:', downloadUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console.log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MedAmine1212 , done

@amjedidiah amjedidiah merged commit 17fcb5c into DevinoSolutions:master Nov 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants