Access Code working on Localhost but not working on actual server (nodechef)

Hi,

For some reason my code works perfectly on my localhost but on an actual server like nodechef I get the following error when using the access code:

error! Body {
url: ‘https://www.patreon.com/api/oauth2/token’,
statusText: ‘UNAUTHORIZED’,
headers:
Headers {
_headers:
{ date: [Array],
‘content-type’: [Array],
‘content-length’: [Array],
connection: [Array],
‘set-cookie’: [Array],
‘cache-control’: [Array],
pragma: [Array],
‘x-patreon-uuid’: [Array],
‘strict-transport-security’: [Array],
‘x-content-type-options’: [Array],
‘expect-ct’: [Array],
server: [Array],
‘cf-ray’: [Array] } },
ok: false,
body:
PassThrough {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 26,
pipesCount: 0,
flowing: null,
ended: true,
endEmitted: false,
reading: false,
sync: false,
needReadable: false,
emittedReadable: true,
readableListening: false,
resumeScheduled: false,
destroyed: false,
defaultEncoding: ‘utf8’,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: { end: [Object], prefinish: [Function: prefinish] },
_eventsCount: 2,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: true,
ended: true,
finished: true,
destroyed: false,
decodeStrings: true,
defaultEncoding: ‘utf8’,
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: true,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: false,
allowHalfOpen: true,
_transformState:
{ afterTransform: [Function: bound afterTransform],
needTransform: false,
transforming: false,
writecb: null,
writechunk: null,
writeencoding: ‘buffer’ } },
bodyUsed: false,
size: 0,
timeout: 0,
_raw: ,
_abort: false }

I am getting this error code after successfully getting the code from the redirect link and using it to call the Patreon client:
var promise = patreonOAuthClient
.getTokens(oauthGrantCode, redirectURL)

var result = await promise.then(function(tokensResponse) ..........

That error status (UNAUTHORIZED) indicates that the error is probably to do with passing an incorrect value, i.e: the code or client_secret. If it’s working in your local environment but not on a server, it’s likely either the server is not configured to deliver request parameters to your code properly, or you haven’t added the correct client_secret to the config.

To debug this properly you’ll need to find out the actual error. If you use the example code, which catches and logs the error, what error do you see logged to the console?

patreonOAuthClient
    .getTokens(oauthGrantCode, redirectURL)
    .then(function(tokensResponse) {
        var patreonAPIClient = patreonAPI(tokensResponse.access_token)
        return patreonAPIClient('/current_user')
    })
    .then(function(result) {
        var store = result.store
        // store is a [JsonApiDataStore](https://github.com/beauby/jsonapi-datastore)
        // You can also ask for result.rawJson if you'd like to work with unparsed data
        response.end(store.findAll('user').map(user => user.serialize()))
    })
    .catch(function(err) {
        console.error('error!', err)
        response.end(err)
    })