Legacy Dev Forum Posts

 View Only

Sign Up

Cannot get ouath/token to work - invalid_respose

  • 1.  Cannot get ouath/token to work - invalid_respose

    Posted 06-05-2025 18:02

    Troy | 2018-11-26 16:09:17 UTC | #1

    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 have entered, URL login.mypurecloud.com.au/oauth/token grant-type = authorizationcode code = the Authcode we we got back from the Authvalidation. redirecturi = http://localhost:8086/oauth/callback

    The Authorization is Basic Auth using the clientId:secret Thanks for any help


    KevinGlinski | 2018-11-26 17:48:18 UTC | #2

    can you share your code?


    tim.smith | 2018-11-26 18:20:28 UTC | #3

    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.


    Troy | 2018-11-26 23:05:28 UTC | #4

    Thanks for looking at this. At this stage I can't get this to work on Postman. This was a typo in the, I am using grant_type in the request.


    Troy | 2018-11-27 00:04:42 UTC | #5

    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(clientid+":"+clientsecret).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); }); });


    tim.smith | 2018-11-27 15:38:50 UTC | #6

    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?


    system | 2018-12-28 15:38:55 UTC | #7

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 4040