我正在尝试使用 Cloudfront HLS 功能设置视频流,但我无法让 Hls.js 在请求中发送我的凭证 cookie。
我已经将 Cloudfront 配置为转发 cookie 和转发访问控制标头。我还设置了我的 S3 CORS 策略以包含 GET、HEAD。
我遇到的问题是,即使我设置了 xhr.withCredentials=true 并且在会话中定义了 cookie,但当我使用 chrome 控制台查看请求时,我可以看到 HLS 请求没有 cookie。结果,我收到了来自 cloudfront 的错误响应,说我需要包含凭证 cookie。
代码:首先,我向我的服务器发出 ajax 请求以生成 cookie。服务器返回三个 Set-Cookies 标头作为会话 cookie 存储在浏览器中:
$.ajax(
{
type: 'GET',
url: 'http://subdomain.mydomain.com:8080/service-
webapp/rest/resourceurl/cookies/98400738-a415-4e32-898c-9592d48d1ad7',
success: function (data) {
playMyVideo();
},
headers: { "Authorization": 'Bearer XXXXXX' }
});
Run Code Online (Sandbox Code Playgroud)
存储 cookie 后,将调用测试函数以使用 HLS.js 播放我的视频:
function test(){
if (Hls.isSupported()) {
var video = document.getElementById('video');
var config = {
debug: true,
xhrSetup: function (xhr,url) { …Run Code Online (Sandbox Code Playgroud)