I'm trying to generate an access token from a refresh token on the OAuth2 of Intuit API (in order to access to the Quickbook API). I achieve to do it in Node.js with the library axios on my laptop, but axios is not available on my server, where my script will be executed. And i doesn't achieve to do it with another library (https, xmlhttprequest, oauth, node-fetch), it'a a non-sense ! Requests return me error 400 Invalid request, so it doesn't help a lot.
Here is the script on axios, which works :
async function quickbookTokenDirect(){
let url = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
let header = {
Authorization:'Basic <Authorization code found on https://developer.intuit.com/app/developer/playground>',
Accept:'application/json',
'Content-Type':'application/x-www-form-urlencoded',
}
let body={
grant_type : 'refresh_token',
refresh_token : '<Refresh token found on https://developer.intuit.com/app/developer/playground>',
}
let result = await axios({method:'post', url:url, headers:header, data:body})
.then( response=>{console.log(response)})
.catch( response=>{console.log(response)})
}
There is the script on https, that doesn't works and i doesn't see why :
async function quickbookTokenHttps(){
const https = require('https')
//let url = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
let header = {
Authorization:'Basic <Authorization code found on https://developer.intuit.com/app/developer/playground>',
Accept:'application/json',
'Content-Type':'application/x-www-form-urlencoded',
}
let body={
grant_type : 'refresh_token',
refresh_token : '<Refresh token found on https://developer.intuit.com/app/developer/playground>',
}
let options = {
hostname:'oauth.platform.intuit.com',
path:'/oauth2/v1/tokens/bearer',
method:'post',
headers:header,
data:body,
//body:body
}
let req = await https.request(options, (res) => {
let result=''
console.log(res.statusCode)
console.log(res.statusMessage)
res.on('data', (chunk) => result +=chunk)
res.on('end', () => {console.log(JSON.parse(result))})
})
.on('error', (err) => {console.log(err)})
.end()
}
If some of you have an idea, it will help me a lot !
I can get the refresh token using Intuit node.js example.
https://github.com/IntuitDeveloper/oauth2-nodejs
The
https.requestheader's filed needs a single quotes And Authorization Basic needs to combine clientID and ClientSecretFrom
To
Get well-known URLs
Response
Add redirect URL in Intuit.com of developer portal in your project at dashboard.
config.json at
oauth2-nodejsdirectoryAt the same directory
Debugging Refresh code in VS code refresh token
refresh token in middleware(client-oauth2)
Browser login
Just login before refresh token
After refresh token
Again the basic Auth code and this line