Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-15671

FIWARE.Question.Tech.axios.post results in Bad request - grant_type:'client_credentials'.

    Details

      Description

      Created question in FIWARE Q/A platform on 07-04-2019 at 11:04
      Please, ANSWER this question AT https://stackoverflow.com/questions/55557557/axios-post-results-in-bad-request-grant-typeclient-credentials

      Question:
      axios.post results in Bad request - grant_type:'client_credentials'

      Description:
      My axios POST method is not working fine. While the call syntax appears to be correct, I guess there is somewhat deep-rooted issue in my specific case. I am trying to get access token using grant_type=client_credentials, using a POST request to fiware IDM server. The call results in 400: bad request.

      curl command works just great. It seems there is a CORS violation when I use simple http request, hence I switched to using node. I tried axios by sending data in separate body, it didn't work either, then someone suggested to send the data in the call using axios.post, it also ended in same problem. Note: I have tried grant_type=password, however, that also met same fate.

      axios.post('https://account.lab.fiware.org/oauth2/token',

      { 'grant_type':'client_credentials'}

      ,

      { headers: { 'Content-Type':'application/x-www-form-urlencoded', 'Authorization': 'Basic xxxx' } }

      ).then((response) =>

      { console.log(response); }

      ).catch((error) =>

      { console.log(error.response.data.error); }

      )

      I expect to get the access token, however, I am getting error 400 as below:

      { message: 'grant_type missing in request body: {}',
      code: 400,
      title: 'Bad Request' }

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2019-04-07 12:06|CREATED monitor | # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2019-04-07 12:06|CREATED monitor | # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2019-04-07 15:06|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2019-04-07 15:06|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2019-04-07 18:05|UPDATED status: transition Finish| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2019-04-07 18:05|UPDATED status: transition Finish| # answers= 1, accepted answer= True

          People

          • Assignee:
            backlogmanager Backlog Manager
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: