HLS Fairplay DRM content I got error to obtain licence key from DRM server by using videojs and videojs-contrib-eme - http-live-streaming

HLS Fairplay DRM Content videojs return Failed to load resource: Origin https:// is not allowed by Access-Control-Allow-Origin. when trying to get licence for HLS fairplay.
I am using Videojs version #7.5.5 and videojs-contrib-eme version #3.5.4
player.src({
// normal Video.js src and type options
src: streamUri,
type: 'application/x-mpegURL',
keySystems: {
"com.apple.fps.1_0": {
certificateUri: certificateUri,
getLicense: function (emeOptions, contentId, keyMessage, callback) {
videojs.xhr({
uri: licenceUri,
method: 'POST',
responseType: 'arraybuffer',
body: keyMessage,
headers: {
'Content-type': 'application/octet-stream',
'utoken-drm': 'fp'
}
}, function (err, response, responseBody) {
if (err) {
callback(err);
return;
}
callback(null, responseBody);
});
}
}
}
});
player.play();'''

This is a CORS error. CORS is described here if you aren't familiar.
Is it your content? Did you set up the licence server?

Related

API call from https node application never reaches the destination

I have a node.js application served over https. I would like to call an API from that application. The API is also served over https and it has been generated using the express-generator.
Unfortunately the call never works. There is no error message. The call never reaches the API.
Strangely enough if I try to call another public API (e.g. https://api.publicapis.org/entries') that is working perfectly.
Here is my call:
const requestBody = {
'querystring': searchQuery,
};
const options = {
rejectUnauthorized: false,
keepAlive: false, // switch to true if you're making a lot of calls from this client
};
return new Promise(function (resolve, reject) {
const sslConfiguredAgent = new https.Agent(options);
const requestOptions = {
method: 'POST',
body: JSON.stringify(requestBody),
agent: sslConfiguredAgent,
redirect: 'follow',
};
fetch('https://192.168.112.34:3003/search', requestOptions)
.then(response => response.text())
.then(result => resolve(result))
.catch(error => console.log('error', error));
});
};
And here is the API which I would like to call:
router.post('/', cors(), async function(req, res, next) {
req.body;
queryString = req.body.querystring;
let data = JSON.stringify({
"query": {
"match": {
"phonetic": {
"query": queryString,
"fuzziness": "AUTO",
"operator": "and"
}
}
}
});
const { body } = await client.search({
index: 'phoneticindex',
body: data
});
res.send(body.hits.hits)
});
What is wrong with my API and/or the way I am trying to communicate with it?
UPDATE: I receive the following error in the fetch catch block: 'TypeError: Failed to fetch'
When I create a request in Postman I receive the expected response.
UPDATE 2: This is most probably an SSL related issue. The webapp is expecting an API with a valid certificate. Obviously my API can only have a self signed cert which is not enough here. How can I generate a valid cert for an API which is running on the local network and not publicly available?
UPDATE 3: I managed to make it work by changing the fetch parameters like this:
fetch(url, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
mode: 'cors',
body: raw,
agent: httpsAgent,
redirect: 'follow',
})
and on the API side I added the following headers:
'Content-Type': 'application/json',
'Access-Control-Allow-Origin' : 'https://localhost:2200',
'Access-Control-Allow-Methods' : 'POST',
'Access-Control-Allow-Headers' : 'Content-Type, Authorization'
I also added app.use(cors()) and regenerated the self-signed certificates.

How to attach blob index tags during a Azure Blob put request?

I followed azure documentation https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob for adding tags during the objects creation in azure blob. Its says that, we have to add 'x-ms-tags' in the request headers. The header that I am attaching to the PUT request is,
headers: {
'Content-Type': file.type,
'x-ms-blob-type': 'BlockBlob',
'x-ms-tags': 'tag1=value1'
}
But these tags are not getting added to the actual blobs. What am i missing here?
Also in the documentaion, it says that 'x-ms-tags' is "Supported in version 2019-12-12 and newer.". Which version they are mentioning here?
Edit1:
Code for uploading the file:
uploadToAzure = function (public_url, sas_token, file) {
return $http({
method: 'PUT',
url: public_url + '?' + sas_token,
ignoreLoadingBar: true,
data: file,
headers: {
'Content-Type': file.type,
'x-ms-blob-type': 'BlockBlob',
'x-ms-tags': 'tag1=value1'
}
})
.then(function (response) {
return response;
}, function (error) {
console.error("error", error)
return error;
});
}
Edit 2:
Edit 2:
Backend code for generating token:
GEM:
gem 'azure-storage-blob'
azure_blob_storage_initializer.rb
AZURE_SAS_TOKEN_GENERATOR = Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(
ENV['AZURE_BLOB_STORAGE_ACCOUNT_NAME'],
ENV['AZURE_BLOB_STORAGE_ACCESS_KEY']
)
Generating token login:
SAS_TOKEN_OPTIONS = { service: 'b', resource: 'b' }.freeze
sas_token = AZURE_SAS_TOKEN_GENERATOR.generate_service_sas_token(blob_path, SAS_TOKEN_OPTIONS.merge(permissions: 'w'))

Problem setting the name of a file when using the Google Drive REST API for resumable uploads

async function createResumableSession(filePath, authClient){
try {
const fileStats = await statsAsync(filePath);
const fileSize = fileStats.size;
const postResult = await new Promise((resolve, reject)=>{
request({
method: 'post',
url: 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable',
followAllRedirects: true,
headers: {
Authorization: "Bearer " + authClient.credentials.access_token,
"X-Upload-Content-Length": `${fileSize}`,
"Content-Length": "0",
"Content-Type": "application/json; charset=UTF-8"
},
body:JSON.stringify({
title: "myfile.backup"
})
}, function (error, response) {
if (error)
return reject(error);
resolve({
statusCode: response.statusCode,
location: response.headers.location,
body: response.body
});
})
})
return {
postResult,
fileSize
}
} catch (error) {
throw error;
}
}
I have this function to create a resumable upload on the Google Drive API, its creating the session correctly but I cant set the file name, after the upload is completed the file name always end as "untitled"
How about this modification?
Modification points:
In your script, from the endpoint of https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable, it is found that you are using Drive API v3. In this case, in order to set the filename, it is required to use the property of name. In your script, title is used. In this case, it is for Drive API v2. So please modify as follows.
Modified script:
Please modify your script as follows.
From:
title: "myfile.backup"
To:
name: "myfile.backup"
Reference:
Files: create
If this was not the direct solution of your issue, I apologize.
Added:
As a simple sample script, I added a sample script. In this sample script, a text file is uploaded using the resumable upload. In this case, the file is uploaded as the filename of "sample". And you can see the text of foo in the uploaded file.
Sample script:
const request = require('request');
const accessToken = "###"; // Please set your access token.
request({
method: 'POST',
url: 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable',
headers: {
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify({name: "sample", mimeType: "text/plain"})
}, (err, res) => {
if (err) {
console.log(err);
return;
}
request({
method: 'PUT',
url: res.headers.location,
headers: {"Content-Range": "bytes 0-2/3"},
body: Buffer.from("foo")
}, (err, res) => {
if (err) {
console.log(err);
return;
}
console.log(res.statusCode)
console.log(res.body)
});
});
Using the property of name, the metadata of file has the filename of sample.
But unfortunately, from your replying, I cannot understand about your current issue. So can I ask you about the detail information about the problem persists? And in order to correctly understand about your situation, can you provide the detail flow and whole script for replicating your issue? Of course, please remove your personal information. By this, I would like to confirm it. If you can cooperate to resolve your issue, I'm glad.

Discord Profil Picture Update from ElectronJS using request PATCH

I'm trying to code an application into Electron JS to allow the person to change their profile picture at the same time on several applications.
For this I use the APIs of each platform.
For Twitter it works correctly, but I block at the level of Discord.
I can make a GET request on the profile, but I can't do a : PATCH/users/#me
https://discordapp.com/developers/docs/resources/user#modify-current-user
I do not know if it's the token that does not offer enough power, because I only asked for Identity as permission on my application.
I tried to pass JSON between true and false,
to add a content type, but I still have the same answer: {code: 0, message: '401: Unauthorized'}
function postDiscord(image) {
const imageDataURI = require('image-data-uri')
let {token} = store.get('discordToken') //get stored token
imageDataURI.encodeFromFile(image)
.then(res => {
request({
method: 'PATCH',
url: 'https://discordapp.com/api/v6/users/#me',
headers: {
'Authorization': 'Bearer '+token,
'User-Agent': 'someBot (site, v0.1)'
},
body: {
'avatar': res
},
json: true
}, function(err, res) {
if(err) {
console.error(err);
} else {
console.log(res.body)
}
}
);
})
}
{code: 0, message: '401: Unauthorized'}
Refering to Discord :https://github.com/discordapp/discord-api-docs/issues/1057
Cannot upload new pics with Oauth :/

Convert Binary Media Data to Buffer in Node JS

I am using a third party api which returns the image in Binary Media Data format. After getting this data, I want to upload this to Google Cloud Storage. To do this, I need to convert this data into Buffer. I've tried multiple times but failed.
I am using NodeJS, npm request module to call api to save image to google cloud storage.
Here is the code:
var binaryData = data;
var bufferData = new Buffer(data);
request({
method: "POST",
url: '/endpoint/upload',
headers: {
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
},
formData: {
filename: {
value: fileBase64,
options: {
filename: 'test.jpg',
contentType: 'image/jpeg'
}
},
}
}, function(err, response, body){
console.log(body);
})
Your post request should follow the template described in the documentation. My post request looks like this:
req = https.request({
method: "POST",
protocol: 'https:',
hostname: 'www.googleapis.com',
path: '/upload/storage/v1/b/[bucket-name]/o?uploadType=media&name=[file-name]',
headers: {
'content-type': 'image/png',
'content-length': Buffer.byteLength(data),
'authorizatoin': Bearer [bearer-token]
}
}, (res) => {
console.log(res.statusCode);
console.log(res.statusMessage);
console.log(res.headers);
}
);
It also looks like you’re lacking authentication. You need to use OAuth 2.0 for Google Cloud Storage. Make sure the Cloud Storage JSON API is enabled too.
You need to obtain your file as a stream. Here's a useful post that specifies how to do that with axios. Once you download the file in the server, you can get it as a Buffer with fs.readFile.

Resources