Proxy a widevine license server using NodeJS - node.js

I'm trying to proxy a Widevine license server using my API, I have made a easy to edit example which is basically a Shaka-player and an API which (should) proxy the license server.
I have this license server which for this example is a sample from shaka-player :
https://cwip-shaka-proxy.appspot.com/no_auth
My API should then do a POST request on the above license server and returns the response to shaka-player to be able to play the video, basically it should acts as a proxy endpoint.
Unfortunately, I get this : INVALID_LICENSE_CHALLENGE, notice that changing the DRM license server from player.configure() of course make it works
I may be wrong but I think that the challenge should be the buffer of the request body converted to base64 that's why I tried to do :
const data = Buffer.from(JSON.stringify(req.body)).toString('base64');
You can find source code here to make it easier to understand
Thanks!
NB: I know there is an exact same topic on that but it didn't get any answer so far.

Related

Serving a HTTP request response as a dialog response - Composer Framework

We are developing a chatbot to handle internal and external processes for a local authority. We are trying to display contact information for a particular service from our api endpoint. The HTTP request is successful and delivers, in part, exactly what we want but there's still some unnecessary noise we can't exclude.
We specifically just want the text out of the response ("Response").
Logically, it was thought all we need to do is drill down into ${dialog.api_response.content.Response} but that fails the HTTP request and ${x.content} returns successful but includes Tags, response and the fields within 1.
Is there something simple we've missed using composer to access what we're after or do we need to change the way our endpoint is responding 2? Unfortunately the MS documentation for FrwrkComp is lacking to say the very least.
n.b. The response is currently set up as a (syntactically) SSML response, this is just a test case using an existing resource.
Response in the Emulator
Snippet from FwrkComp
Turns out it was the first thing I tried just syntactically correct. For the case of the code given it was as simple as:
${dialog.api_response.content[0].Response}

Use nodeJS server with symfony

I have a huge symfony app and I wanted to add some feature that I could only do with a nodeJS server .
So I have a big JSON file which result from my nodeJS run, this file have to go in Symfony.
And symfony have to be able to send some pdf file to the node server (the one which will be transform in JSON by my node server).
Is anyone have some starting idea ?
thansk for help :D
No one is going to be able to provide a full answer with so few details, but generally speaking messaging and remote procedure calls are excellent for interop between parts of a large app.
You could send a message from Symfony (which includes the path of the PDF, or the contents itself), and node will provide the result. You can encode that as JSON, and send it as an answer.
RabbitMq is widely supported, allows both produce-consume or RPC-style use.

Node.Js : How to log a request's body without access to the Request object

I'm currently using a framework in Node.js ( the botbuilder module from Microsoft Bot Framework) which uses the request[2] module to make HTTP requests.
I'm encountering a problem : this framework seems to send a malformed JSON to Microsoft's servers, but I fail to see why and what is this JSON message made of.
So I'm looking for a way to log those messages, to take a peek at this malformed JSON, as I don't have access to the request object (unless I heavily alter the framework code, which is not something one shall do)
So far, I'm able to log the response body (by adding request to the NODE_DEBUG environment variable), but not the original request body. I did try a tcpdump on our server but since it's all HTTPS there's nothing I can use there.
Any idea / tool that might help ?
Thanks for your time.
Use Node.js middleware to log all your requests. For example, you could use the module request-debug.
Another popular request logging middleware worth knowing about is Morgan, from the Express.js server team.

How to prevent 3rd part services from using my API?

I have developed a front-end interface using Aja(AngularJS) and HTML5. Right now, I send an HTTP get request to my backend server which returns some data based on the GET parameters.
Since the URL is exposed in the Javascript file, I believe anyone could just use the URL to create there own API to fetch the data. How can I prevent such things ?
One way I could think of is that now instead of directly sending the request to the backend server, an application server could be used (hosting the HTML as well). The Ajax request would then be sent to this server (PHP script ?) which would in turn forward the request to the backend server and return the result to the UI. To prevent 3rd party services, I can disable cross origin requests on my application server.
Is this the correct way to solve my problem or are there better ways to do this? I am concerned that this would unnecessarily create another hop (internal though) for requests.
Note: The backend is running Apache Tomcat
In APIs that are not open to the world the user has to authenticate first in order to use it, see for example https://stripe.com/docs/api#authentication or http://dev.maxmind.com/geoip/geoip2/web-services/ -> Authorization

Node.js and HTML5 Audio

I'm trying to get my node.js server to server up audio files for the HTML5 audio tag. Currently I'm referencing audio files via an express staticProvider, but this will allow the sound to play once and then never again.
From what I've been able to gather in order for the sound to work properly with seeking or looping I need to provide the "Content-Range" header when my audio file is requested. I highly doubt that the express staticProvider is doing this for me, so it would seem that I need to serve the file up using custom code. Unfortunately I'm fairly new to node.js and things like serving files are still a little beyond me. Can anyone offer some advice on how I can provide the appropriate metadata for my audio files?
[EDIT] (Removed old server code since it won't do anyone any good!)
Sorry, I don't typically ask questions this broad, but I'm really at a loss as to where to start with this one. Any suggestions?
[SOLUTION]
So it appears that the solution is just to use updated software. I was trying express rather than the built-in connect HTTP middleware because I thought connect wasn't doing static file serving right. Turns out, I was just looking at the documentation for a newer version of connect while the version that comes with node is a bit older. Once I updated my connect library (I just used npm to install the latest, for those that are curious), the following worked beautifully:
var connect = require('connect');
var server = connect.createServer(
// If your server errors on this line, saying it doesn't know what
// "static" is you need to get the latest connect!
connect.static(__dirname + '/public')
);
server.listen(PORT);
The static serving logic is done by the underlying connect server (using its static middleware). There is code for 'Content-Range' headers (see here, about line 148), but these headers are only set when the underlying client (in your case, the browser's HTML5 implementation) sends the correct request headers.
Maybe this post from google groups can help you out. The topic is slightly different (video streaming), but i think the core of the problem is about the same.

Resources