Hi, RC team, hope you're doing well!
I've been having an issue getting JWT authorization to work. I'm able to successfully get an access token in Postman, but in my code, I only get error code OAU-250 (unsupported grant type). I've tried to follow the directions of the technical guide and by looking at other posts here.
In Postman, I'm using a POST request with endpoint: https://platform.devtest.ringcentral.com/restapi/oauth/token
Authorization: I entered Basic Auth with my clientId and clientSecret as Username and Password, respectively.
Headers are auto-generated by Postman; I don't add any custom ones. Note that when Postman creates the Authorization header, its value becomes "Basic " and then the base64 encoding of my clientId:clientSecret. I can confirm here too that Content-Type is "application/x-www-form-urlencoded".
Finally for the Body, where I've chosen x-www-form-urlencoded, the grant_type is "urn:ietf:params:oauth:grant-type:jwt-bearer" and the assertion is my JWT.
All of this results in a successful POST request where I get the appropriate access/refresh tokens, scope, and all.
In the code, however, I try to follow the above as close as possible, but I keep on getting that OAU-250 error. Note that I have to use ScriptEase, a dialect of JavaScript.
My API Configuration looks like the following [identifying info omitted]:
var config = {
"url": "https://platform.devtest.ringcentral.com/restapi/oauth/token",
"method": "POST",
"timeout": 0,
"headers": {
"Accept":"application/json",
"Authorization": "Basic " + uclientId:clientSecret, base64 encoded together],
//"Content-Type": "application/x-www-form-urlencoded",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
"body": {
//"grant_type":"urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer",
"grant_type":"urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion":omy JWT],
}
};
// I then try to make my request with:
var client = new HttpClient(config.url);
var request = new HttpRequest('POST', '');
request.addHeaders(config.headers);
request.setBody(config.body.toString(), "application/x-www-form-urlencoded");
var response = client.sendRequest(request);
As seen above, I've tried both variants of grant_type (with and without the %3A character for the colons), and nothing I've tried on my end has worked. The response comes back as OAU-250 mstatus code 400]. Would you happen to know what may be the cause of this or what I should try changing? Please let me know if you have any questions.
Wishing you all the best!