microsoft / skype-interviews-docs

Sample code showcasing how to use the Skype Interviews API
MIT License
12 stars 14 forks source link

Token error - err:8 #7

Open Aayush-N opened 6 years ago

Aayush-N commented 6 years ago

Hi, I'm getting the response: Token error - err:8 returned on adding any JSON data in the body. It runs fine with {} in the body but not with any data. My code is here

manushijoshi66 commented 6 years ago

I am getting the same error. Did you resolve it?

Aayush-N commented 6 years ago

No, I haven't been able to solve it yet. Have you?

MakarGlavanar commented 5 years ago

I think you getting this error, because in your request you should put sha256 hash from your JSON body in sub field in token. Hash that you parse in your code, generated from {} that's why everything works fine when your body is {}.

gcicoira commented 5 years ago

I have the same problem with json different from '{}': string(19) "Token error - err:8" NULL

This is my code: `<?php error_reporting(E_ALL); ini_set('display_errors', 1);

// using composer https://getcomposer.org/ require DIR . '/vendor/autoload.php'; // JWT PHP Library https://github.com/firebase/php-jwt use \Firebase\JWT\JWT;

$option = '{"company":{"name": "xxxxxxxxxxx"}}'; //$option = '{}';

function generateToken($content) { $API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $API_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $payload = array( "jti" => getGUID(), "iss" => $API_KEY, "iat" => time(), "sub" => hash('sha256', $content), "exp" => time() + 10 // 10 seconds expiration ); return JWT::encode($payload, $API_SECRET); }

function getGUID(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45); $uuid = chr(123) .substr($charid, 0, 8).$hyphen .substr($charid, 8, 4).$hyphen .substr($charid,12, 4).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12) .chr(125); return $uuid; } }

function generateInterview ($option) { //die($option); $ch = curl_init('https://interviews.skype.com/api/interviews'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, '{}'); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . generateToken($option), 'Content-Type: application/json' ));

$response = curl_exec($ch);
var_dump($response);

$response = json_decode($response);
curl_close($ch);
return $response;

} var_dump(generateInterview($option)); ?>

`

gcicoira commented 5 years ago

SOLVED!!!!!!

`<?php error_reporting(E_ALL); ini_set('display_errors', 1);

// using composer https://getcomposer.org/ require DIR . '/vendor/autoload.php'; // JWT PHP Library https://github.com/firebase/php-jwt use \Firebase\JWT\JWT;

//$option = '{"company":{"name": "xxxxxxxxxxx"}}'; //$option = '{}'; $option = '{"capabilities":{"codeEditor": true,"notes": true}}';

function generateToken($content) { $API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; $API_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; $payload = array( "jti" => getGUID(), "iss" => $API_KEY, "iat" => time(), "sub" => hash('sha256', $content), "exp" => time() + 10 // 10 seconds expiration ); return JWT::encode($payload, $API_SECRET); }

function getGUID(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45); $uuid = chr(123) .substr($charid, 0, 8).$hyphen .substr($charid, 8, 4).$hyphen .substr($charid,12, 4).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12) .chr(125); return $uuid; } }

function generateInterview ($option) { //die($option); $ch = curl_init('https://interviews.skype.com/api/interviews'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $option); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . generateToken($option), 'Content-Type: application/json' ));

$response = curl_exec($ch);
var_dump($response);

$response = json_decode($response);
curl_close($ch);
return $response;

} var_dump(generateInterview($option)); ?>`