Hi, dear friends.
I am makeing some javascript code which is able to access to box with JWT authentication.
My script is like bellow:
====================================================================================
var pHeader = {
'alg':'RS256',
'typ':'JWT',
'kid':'wcd514pc'
};
var sHeader = JSON.stringify(pHeader);
var pPayload = {
'iss':'rewgy69ghdgzvgesjj78ffdaeewubui', //client_id
'sub':'13584135', //enterprise id
'box_sub_type':'enterprise', //set to "enterprise" because sub is enterprise id
'aud':'https://api.box.com/oauth2/token', //
'jti':'B5ujJ7T12VyQd1bPkf99', //set by client secret, because in where I can get this param, ?...
'exp':***number removed for privacy***5
};
var sPayload = JSON.stringify(pPayload);
var sPrvKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\n
Hmzy4oNF\nUyKjjruW0CAl...........................................\n
.......................................................................................\n
6uk=\n
-----END ENCRYPTED PRIVATE KEY-----\n";
var sJWS = KJUR.jws.JWS.sign(null, sHeader, sPayload, sPrvKey, '6945f416c14c7a1b004aee47195a5e48');
var xhttp = new XMLHttpRequest();
xhttp.open("POST", encodeURIComponent("https://api.box.com/oauth2/token"), true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("charset", "utr-8");
var params = "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion="+sJWS+"&client_id=rewgy69ghdgzvgesjj78ffdaeewubui&client_secret=B5ujJ7T12VyQd1bPkf99";
xhttp.send(encodeURIComponent(params));
====================================================================================
That result that is taken from server is like bellow:
====================================================================================
{
"error": "invalid_request",
"error_description": "Invalid grant_type parameter or parameter missing"
}
====================================================================================
Please someone teach me about what was I writing wrong script and why did I get invaild param message from box server.
Thanks.