Bungie-net / api

Resources for the Bungie.net API
Other
1.21k stars 92 forks source link

[Missing required parameter grant_type / AuthorizationCodeInvalid] Unable to send POST to get tokens #1463

Closed RunkDowN closed 3 years ago

RunkDowN commented 3 years ago

Im trying to make a small discord bot with Banshee mods. To get Vendors I need an OAuth token. I've made a https localhost and getting the autorization_code after redirect. Then I need to make a POST to https://www.bungie.net/Platform/App/OAuth/Token/ with those cliend_id, client_server and code. But the request returning

   data: {
      error: 'invalid_request',
      error_description: 'Missing required parameter grant_type'
    }

My function is:

async function getTokens() {
  try {
    const config = {
      method: 'post',
      url: `https://www.bungie.net/Platform/App/OAuth/Token/`,
      headers: { 
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Basic {base64{mycode: client_id:client_secret}}',
      },
      data: {
        grant_type: 'authorization_code',
        code: '{code from redirect endpoint localhost}'
      }
  }

    let res = await axios(config)
  } catch (error) {
    console.log(error)
  }
}

If we will change data to string to look like this: data: 'grant_type=authorization_code&code={code from redirect endpoint localhost}'

I got an error

   data: {
      error: 'invalid_grant',
      error_description: 'AuthorizationCodeInvalid'
    }

Am I missing something? Would be thankful for any help (:

RunkDowN commented 3 years ago

Sorry guys Found out that token from endpoint is 1-time-use and need to be re-generated every time