I'm developing a web site for provide a video on demand service by using React and AWS S3.
I need to must authorize to watch videos.
So I consider to use signed cookie when requesting.
To request using curl was successful.
curl -H 'Cookie:CloudFront-Policy=eyJTd*******************;CloudFront-Signature=b8wt************************************; CloudFront-Key-Pair-Id=AP**********' http://*********.cloudfront.net/hogehoge.m3u8
But I can't get file at React.
My code is there.
export function Movie(){
document.cookie = `CloudFront-Key-Pair-Id=${"AP**************"}; `
document.cookie = `CloudFront-Policy=${"eyJT*****************"}; `
document.cookie = `CloudFront-Signature=${"b8wt****************"}; `
<ReactPlayer
url={"http://******.cloudfront.net/hogehoge.m3u8"}
controls
config={{
file: {
hlsOptions: {
xhrSetup: function(xhr: any, url: any) {
xhr.withCredentials = true // send cookies
}
}
}
}}
>
}
Error message on Chrome(Image)
Request URL: http://*****.cloudfront.net/hogehoge.m3u8
Referrer Policy: strict-origin-when-cross-origin
Connection: keep-alive
Content-Length: 146
Content-Type: text/xml
Date: Tue, 27 Oct 2020 05:54:03 GMT
Server: CloudFront
Via: 1.1 *********.cloudfront.net (CloudFront)
X-Amz-Cf-Id: *******
X-Amz-Cf-Pop: NRT12-C3
X-Cache: Error from cloudfront
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: ja-JP,ja;q=0.9,en-JP;q=0.8,en;q=0.7,en-US;q=0.6
Connection: keep-alive
DNT: 1
Host: ********.cloudfront.net
Origin: http://localhost:3000
Referer: http://localhost:3000/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
The request looks like not including cookies.
How can I resolve the issue?