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

Send cookies with hls #319

Closed
thm-design opened this issue Feb 5, 2018 · 6 comments
Closed

Send cookies with hls #319

thm-design opened this issue Feb 5, 2018 · 6 comments

Comments

@thm-design
Copy link

thm-design commented Feb 5, 2018

Does react-player currently support sending cookies (cloudfront) with HLS files in any way?

@cookpete
Copy link
Owner

cookpete commented Feb 8, 2018

As of 1.1.2 you can do:

<ReactPlayer
  url={url}
  config={{
    file: {
      hlsOptions: { 
        xhrSetup: function(xhr, url) {
          xhr.withCredentials = true // send cookies
        }
      }
    }
  }}
/>

Based on the API doc here: https://github.com/video-dev/hls.js/blob/master/doc/API.md#xhrsetup

Make sure that the server you are serving from is set up correctly to avoid CORS errors, eg:

Failed to load https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

@thm-design
Copy link
Author

Thanks!

@dudeful
Copy link

dudeful commented Jan 6, 2021

I'm facing this issue right now and I'm running out of hope. Can someone who was able to fix this issue give me some light?

I'm using Amazon CloudFront to deliver my HLS VOD streaming for which the origin is an S3 bucket. Everything works beautifully while the CloudFront distribution is not protected, but I'm not being able to play the videos when I try to use Signed Cookies. Both my front-end and my back-end are running locally in a dev environment (windows + chrome). The 3 required cookies are being set on the browser the way they should, but they are never being sent in the request header to CloudFront.

I already tried this:

<ReactPlayer
  url={url}
  config={{
    file: {
      hlsOptions: { 
        xhrSetup: function(xhr, url) {
          xhr.withCredentials = true // send cookies
        }
      }
    }
  }}
/>

but had no luck with it.

I have spent a few hours by now trying to make this work and still, the problem remains: the cookies are not being sent. Feeling extraordinarily dumb as I'm "sure" is trivial stuff.

I don't think it would be useful to post my code here since I'm 99% sure my only problem is that I'm not succeeding in setting the cookies in the CloudFront request headers.

@arpwal
Copy link

arpwal commented Jan 11, 2021

@dudeful did you find a solution? I'm trying to setup hls vod protected streams with GCP and am facing similar issues.

@dudeful
Copy link

dudeful commented Jan 11, 2021

@arpwal I found out that it is actually a restriction regarding the origin, in my case different cloudfront distributions.

If I understood it right, in order to send the signed cookies along with the cloudfront request for the files, you need your frontend on the same domain that the cloudfront distribution that's serving the files is. This can be achieved by setting a custom domain on your distribution setup. After that the cookies should be sent along with the request as usual.

There's a few tutorials explaining the whole process with successful results, but in general all of them pointed to the same direction as I poorly explained above.

I didn't implemented it yet, still recovering from the last trial and its endless frustrations to be honest so I'm delaying for a little while, but as soon as I do fix it I will send the results here and probably open an answered question on stackoverflow for people facing the same issue.

Also, this issue seems to not be correlated to react-player, at least not in my case, but since probably a lot of people are going to face this issue and come here looking for a solution, maybe it should remain open for now I guess.

@vinodhoney
Copy link

vinodhoney commented Jan 11, 2021

@dudeful / @arpwal ..Please share the complete code to pass the all 3 cookies (CloudFront-Key-Pair-Id,CloudFront-Signature,CloudFront-Policy) in HLS player.

Thanks in advance!

albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
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

No branches or pull requests

5 participants