Santosh
Santosh

Reputation: 2333

Authentication in Chromecast CAF Receiver application

I have a help URL which is to be authenticated with a token before playing it. How can I add a token header to a receiver CAF application? I searched in the documentation but couldn't find any reference of authentication for a receiver CAF application.

In V2 player we can intercept the request with updateSegmentRequestInfo as shown below but im not sure how to do it with CAF Application. Can someone help?

host.updateSegmentRequestInfo = function(requestInfo) {
            console.log("Inside updateSegmentRequestInfo");
            requestInfo.withCredentials = true;
            requestInfo.headers = {};
            requestInfo.headers['token'] = window.token;
            console.log("token sent");
        };

Upvotes: 3

Views: 1887

Answers (1)

SamSol
SamSol

Reputation: 2881

Set cookies on player load event.

Use this code:

const context = cast.framework.CastReceiverContext.getInstance();
const playerManager = context.getPlayerManager();
const castOptions = new cast.framework.CastReceiverOptions();

let playbackConfig = (Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig()));

playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD,
request => {

  // Set cookies here. 
  // No need to pass cookies into header in each segment.

  //  console.log("content id:", request.media.contentId);
  //  Set your segment valid hls format : below is example:
  //  Refer other format:
  //  https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.messages#.HlsSegmentFormat

  request.media.hlsSegmentFormat = cast.framework.messages.HlsSegmentFormat.TS;

  return request;
});

playbackConfig.manifestRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
};

playbackConfig.segmentRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
  };

playbackConfig.licenseRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
};

castOptions.playbackConfig = playbackConfig;
context.start(castOptions);

Upvotes: 3

Related Questions