I have tried to get the Authorization_code grant to work using the sample Node.js code provided.
I cannot get a valid access token back from the login.mypurecloud.com.au similar to another closed topic on the forum.
I have tried re-formatting the code to ensure the packet is as per the documentation as it appeared the sample code did not work.
I then tried Postman and using x-www-form-urlencoded and keep getting the same response.
The latest correlation Id is,
inin-correlation-id →7e3c899b-f027-4aca-7cb8-9d9af0a1b799 if that helps.
I noticed in your post you are using grant-type, not grant_type. That form param is supposed to use an underscore. If that's not the issue, as Kevin asked, please share your code for your login process.
This is a version of code, modified from the provided example. I have tried a few approaches to try and get the request correctly formatted the form data and authorization. This was the latest version where I tried to force the headers and coding.
app.get("/oauth2/callback", function(req,res){
var authCode = req.query.code;
var tokenFormData = grant_type=authorization_code&code=${authCode}&redirect_uri=http://localhost:8086/oauth2/callback;
var postData = {
url:'https://login.mypurecloud.com.au/oauth/token',
headers: {
"content-type" : "application/x-www-form-urlencoded",
"Authorization":"Basic "+new Buffer.from(client_id+":"+client_secret).toString("base64")
},
body: tokenFormData
}
//post back to /oauth/token with the client id and secret as well as the auth code that was sent to us.
request.post(postData, function(err,httpResponse,body){
console.log(body);
var tokenResponse = JSON.parse(body);
var sessionId = uuid.v4();
sessionMap[sessionId] = tokenResponse.access_token;
res.cookie('session', sessionId);
});
For the postman config, be sure you're using https in your URL; auth and the API only work over HTTPS. What is the error body you're getting? It should contain a message indicating what was wrong with the request.
For your code, what's the error body you're getting there?