Skip to content
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

SharePoint: Non-core OneDrive types cannot be embedded #1

Open
r-a-y opened this issue Feb 5, 2021 · 24 comments
Open

SharePoint: Non-core OneDrive types cannot be embedded #1

r-a-y opened this issue Feb 5, 2021 · 24 comments
Labels
needs-docs Requires documentation to work properly sharepoint Issues related to SharePoint

Comments

@r-a-y
Copy link
Member

r-a-y commented Feb 5, 2021

When using SharePoint/Office 365, it appears items that are not a core OneDrive type (Word, Powerpoint, Excel, Visio) will not embed properly due to a cross-domain iframe request restriction:

So basically any file like an image, audio or PDF will not work without further SharePoint configuration. This also includes OneNote.

There's a SharePoint UserVoice suggestion here that is worth keeping an eye on: https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/37212052-ability-to-use-frame-iframe-object-embed

@r-a-y r-a-y added needs-docs Requires documentation to work properly sharepoint Issues related to SharePoint labels Feb 5, 2021
@r-a-y
Copy link
Member Author

r-a-y commented Feb 15, 2021

As a workaround, I looked into two things:

  1. Using the OneDrive preview URL for embedding: https://docs.microsoft.com/en-us/graph/api/driveitem-preview?view=graph-rest-1.0

    This works well, however I found that the preview URLs expire after only five minutes.

  2. Using the thumbnail of the OneDrive item (https://docs.microsoft.com/en-us/graph/api/driveitem-list-thumbnails?view=graph-rest-1.0) and linking to the item

    This works as well, but suffers from a similar problem as the preview URLs. The thumbnails expire within 24 hours. Thumbnails only appear to work for images and PDFs. Audio and OneNote files do not have thumbnails.

If we wanted to refresh either the preview URL or thumbnail, we'd have to ask the user to authenticate separately at least once (similar to how we tell a user to allow us to access their GDrive). Then, whenever either the preview URL or thumbnail expires, we would have to fetch the new URL on the user's behalf. The Azure app would also need to add additional API permissions so we can make these calls.

The alternative to using the preview URL or thumbnail is simply displaying an icon of the file type with the filename.

@mrjarbenne
Copy link
Member

Let's go with an icon for the file type displayed in the post. That seems like the least taxing to the system. That matches what happens in Brightspace as well, so the behaviour will be familiar:

2021-04-26_09-56-28

@r-a-y
Copy link
Member Author

r-a-y commented May 4, 2021

Apologies for the delay in this. I've put up some updates on production.

Here's an example with a PDF file:

PDF example

The icons are exactly the ones used by OneDrive. I've tried to account for most file types for the icons such as audio, video, photo, zip, html, rtf, etc. Let me know if I'm missing any file types. Also let me know if the styling is okay.

You might need to purge your browser cache and will need to re-select your file in the OneDrive block to see the changes.

Also, let me know if you want me to change the "Find out how to find your shared OneDrive link" URL to something else. If you record a video on hwdsb.tv, I can change the link to that. Otherwise, I can write some placeholder documentation.

@mrjarbenne

This comment has been minimized.

@r-a-y

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@r-a-y

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@r-a-y

This comment has been minimized.

@mrjarbenne

This comment has been minimized.

@r-a-y r-a-y changed the title SharePoint: Non-core OneDrive types cannot be embedded without further configuration SharePoint: Non-core OneDrive types cannot be embedded May 8, 2021
@r-a-y
Copy link
Member Author

r-a-y commented Jun 23, 2021

Unfortunately, that will not work for the same reason why it cannot be embedded in an iframe:

Refused to frame 'https://hwdsbonca-my.sharepoint.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.office.com *.stream.azure-test.net *.microsoftstream.com".

What's interesting is why SharePoint administrators cannot register their own domains to the CSP and why core OneDrive files are not affected by this CSP.

@r-a-y
Copy link
Member Author

r-a-y commented Aug 14, 2023

While working on migrating our videos to SharePoint, I stumbled across a workaround to get other OneDrive items to embed from SharePoint. I only tested this method with a video, but this can probably work for other file types as well.

This would require embedding two <iframe> items. The first embed would be the "Anyone with the link can view" sharing link generated by OneDrive. The sharing URL generally resembles something like hxxps://XXX.sharepoint.com/:v:/g/personal/XXX/SOMEID. Embedding the sharing link helps to set the necessary authentication cookies needed to view the main embed. We would need to hide this item from display.

The main embed uses the following URL format:

hxxps://XXX.sharepoint.com/personal/XXX/_layouts/15/embed.aspx?UniqueId=XXX.

I'm not sure if the 15 has any special significance or not, however the UniqueId is something we need to query OneDrive for and is not the same as SOMEID from the first embed. I can probably query this info from the OneDrive File Picker.

Also I believe this method would require that downloads are not disabled for the specific OneDrive item. Needs further testing, but thought I'd document this somewhere.

@r-a-y
Copy link
Member Author

r-a-y commented Oct 19, 2023

@mrjarbenne - I've got a first pass of the double <iframe> trick for testing on production. You might need to purge your browser cache to get the new javascript.

You'll need to use the OneDrive block to select a video into a post. The Gutenberg live preview isn't updated yet, but if you save as a draft and view the post preview, you should be able to view the video. Older video embeds will not work as I need to save the unique ID as a block attribute. Once I get some confirmation, I'll try and get the Gutenberg live preview working to display the video and open this up to audio, images and PDFs as well.

@mrjarbenne
Copy link
Member

Cleared my cache. It's looking good from my logged in view, but logged out in a private browser window (and on a colleagues browser) I'm seeing what might be a login page from Microsoft, but it's not rendering properly:

https://sandbox.commons.hwdsb.on.ca/2023/10/video-on-onedrive-test/

2023-10-19_12-12-01

@r-a-y
Copy link
Member Author

r-a-y commented Oct 19, 2023

but logged out in a private browser window (and on a colleagues browser) I'm seeing what might be a login page from Microsoft, but it's not rendering properly

Hmm, I'm getting that as well, but after refreshing the page, the video shows up. Can you confirm if that is the case?

Maybe I can add a page refresh after the initial page load is done so the cookies are set before the embed is ready to show up?

@mrjarbenne
Copy link
Member

Yes. Refreshing the page seems to bring it to life.

@r-a-y
Copy link
Member Author

r-a-y commented Oct 19, 2023

I made a little error when rendering the second <iframe>. The video embed should now recognize the cookies from the first <iframe> and automatically refresh on its own. Can you test again?

@mrjarbenne
Copy link
Member

I think that fixed it. It seems to be working nicely now.

@r-a-y
Copy link
Member Author

r-a-y commented Oct 23, 2023

I've opened up the double iframe technique to audio, images and PDFs. I still need to get the Gutenberg preview working with this new technique, so for now, you will have to save as a draft or publish the post to view the change on the frontend.

I found one niggle while testing when logged out. If you are viewing a few, different embeds on the same page when logged out, only one of the embeds will render correctly unless you refresh the page again. You can test at sandbox.commons.hwdsb.on.ca in a private browser. Let me know if this is important to address.

@mrjarbenne
Copy link
Member

Here's a post with some test content: https://sandbox.commons.hwdsb.on.ca/2023/10/embed-test/

When the post first loaded only the bottom option appeared. When I refresh (multiple times) only the second to last option is available:

2023-10-27_11-49-06

It does look great when logged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-docs Requires documentation to work properly sharepoint Issues related to SharePoint
Projects
None yet
Development

No branches or pull requests

2 participants