When setting up the SPO Public CDN using PnP PowerShell, a 403 error shows when trying to access the URL. It shows an HTTP address instead of an HTTPS address. In SPfx, a 406 error shows from a JS fetch call.
Here's the setup process:
- Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/SiteName
- Set-SPOTenant -PublicCdnEnabled $true
- Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl "Sites/SiteName/SiteAssets/CDN"
- Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl "Sites/SiteName/CDN"
- Upload test.css to https://tenant.sharepoint.com/sites/SiteName/CDN/Files/
- Make a public link to the file.
- Upload test.css to https://tenant.sharepoint.com/sites/SiteName/SiteAssets/CDN/Files/
- Make a public link to the file.
- Browse to https://tenant.sharepoint.com/_vti_bin/publiccdn.ashx/url?itemurl=https://tenant.sharepoint.com/SiteName/CDN/Files/test.css
- Capture returned URL: https://publiccdn.sharepointonline.com/tenant.sharepoint.com/1937006161eeae8fe.../Files/test.css
- Browse to https://tenant.sharepoint.com/_vti_bin/publiccdn.ashx/url?itemurl=https://tenant.sharepoint.com/SiteName/SiteAssets/CDN/Files/test.css
- Capture returned URL: https://publiccdn.sharepointonline.com/tenant.sharepoint.com/2347006161eeae8fe.../Files/test.css
- Browser to public CDN: https://publiccdn.sharepointonline.com/tenant.sharepoint.com/1937006161eeae8fe.../Files/test.css
- Get HTTP 403 error:
Access Denied
You don't have permission to access "http://publiccdn.sharepointonline.com/tenant.sharepoint.com/1937006161eeae8fe.../Files/test.css" on this server. (shows HTTP instead of HTTPS)
Reference #18.2eec3817.1654696621.25fdf7ed
The same error happens for the SiteAssets public link. Why is SPO forcing HTTP on public CDNs?
I also tried the following commands, which provided the same results:
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl "Sites/SiteName/SiteAssets/CDN"
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl "Sites/SiteName/CDN"
Also tried making public links to the CDN folder and Files folder.
Documentation says you can only access the URL from within SPO, but in an SPfx solution, trying to access a public CDN URL renders an HTTP 406 error. Here are two GitHub tickets that have not been resolved that are exactly related:
https://github.com/SharePoint/sp-dev-docs/issues/6039
https://github.com/SharePoint/sp-dev-docs/issues/5981
I'm really trying to get JSON data, and have tried to fetch the data as a MIME file JSON, CSS, TXT, and JPG. A different project allows me to use PNPjs to fetch JSON from a SP document library. This public CDN approach to allow data to pull centralized JSON into multiple extranet client sites has me stomped.