0

I am using the xero-node module to create an app for Xero with NodeJS.

For some reason every single request for a refresh token is coming back as invalid grant

i have been taken the code and made the callback attempt to grab the refresh straight after i do the auth so I can ensure thats its the latest token and still does the same thing.

Code is below this method is called when Xero passes back to the app (callbackURL)

The error i get is "invalid_grant" it does not give any other errors and there is no errors logs in Xero so very unhelful.

exports.callback = async function (req, res) {
    const tokenSet = await xero.apiCallback(req.url);

    try {
        const newTokenSet2 = await xero.refreshWithRefreshToken('ClientID, 'ClientSecret', tokenSet.refresh_token);
    }
    catch(error){

        console.log(`ERROR  refresh: \n ${JSON.stringify(error.response.body, null, 2)}`);

    };




    ///console.log(tokenSet);

};

Any ideas ?

duckdivesurvive
  • 177
  • 1
  • 8

1 Answers1

0

Without seeing more of your code for context it's bit tough to tell. I'm assuming you're not actually sending 'ClientID' and 'ClientSecret' as strings.

I would refer you here for refreshing with a fully initialized client leveraging openid-client: https://github.com/XeroAPI/xero-node-oauth2-app/blob/f1fbd3a08e840e54e8ce57f7050ddde6686208d8/src/app.ts#L233

Or here, to initialize an empty client and refresh by passing the client, secret, and refresh_token: https://github.com/XeroAPI/xero-node-oauth2-app/blob/f1fbd3a08e840e54e8ce57f7050ddde6686208d8/src/app.ts#L236

I think what's happening is that you're using the second method but with an already initialized client. Again, tough to tell with limited context. If this doesn't resolve it please post more detail.

Rett Behrens
  • 181
  • 1