Post

Replies

Boosts

Views

Activity

DeviceCheck: Authorization Token Issue
Hi everybody, I am trying to make DeviceCheck work in Javascript. But I keep on getting this issue: Unable to verify authorization token Following is my code: versionRouter.post('/update_two_bits', function(req, response) { console.log('hereeee'); console.log("\n\n\n\n\n"); var dctoken = req.body.token; var bit0 = req.body.bit0; var bit1 = req.body.bit1; console.log("Updating two bits to:"); console.log("bit0: "+bit0); console.log("bit1: "+bit1); var jwToken = jwt.sign({}, cert, { algorithm: 'ES256', keyid: keyId, issuer: teamId,}); console.log('jwToken',jwToken); // Build the post string from an object var post_data = { 'device_token' : dctoken, 'transaction_id': uuidv4(), 'timestamp': Date.now(), 'bit0': bit0, 'bit1': bit1 } // An object of options to indicate where to post to var post_options = { host: deviceCheckHost, port: '443', path: '/v1/update_two_bits', method: 'POST', headers: { 'Authorization': 'Bearer '+jwToken } }; // Set up the request var post_req = https.request(post_options, function(res) { res.setEncoding('utf8'); console.log(res.headers); console.log("statusCode: "+res.statusCode); var data = ""; res.on('data', function (chunk) { data += chunk; }); res.on('end', function() { console.log(data); response.send({"status": res.statusCode}); }); res.on('error', function(data) { console.log('error'); console.log(data); response.send({"status": res.statusCode}); }); }); // post the data post_req.write(new Buffer.from(JSON.stringify(post_data))); post_req.end(); }); Kindly provide some solution for it.
0
0
664
May ’22