XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
91 stars 65 forks source link

refresh the token? #218

Closed kunallibra closed 3 years ago

kunallibra commented 3 years ago

Hi,

I am always facing this problem after few days.

I am using this it on laravel and have a Xero.json file. My token gets expires after few days so I was thinking is there any where where it automatically refreshes the token? I have to work around through the postman then get the new access and refresh tokens and paste. This is not logical or may be I am not using it correctly.

I really appreciate if you can direct with in the right direction as I have to always update my json file manually.

thanks heaps.

anchordigi commented 3 years ago

I'm nothing to do with this API, but I have just used it for the first time in the last few days and had to figure out refreshing the token stuff.

You need to store the token somewhere that can be updated programatically, because when you use the refresh token to get a new access token, the previously stored token in your json file is now redundant.

So for example, I store my token in the database, and then when the token expires I get a new token (using the refresh token), and overwrite the token in the database with the new one.

SidneyAllen commented 3 years ago

@kunallibra - thank you for your question. @anchordigi is correct that when performing a token refresh Xero returns a new access_token and new refresh_token. For this reason, you'll need persistent storage for your tokens.

Xero will be releasing Custom integrations in the next 30-60 days. that will support the client_credential grant and long lived access tokens. You can read about it here. https://developer.xero.com/announcements/custom-integrations-are-coming/

kunallibra commented 3 years ago

Hello @anchordigi , @SidneyAllen I am saving the tokens in a json file located inside the storage folder in the root directory. I am not able to understand and get the right info for over a week now. If i manually get the access_token, id_token and refresh token by accessing it from postman and then paste it in the json file it work fines, but if the token expires, it does not do it automatically. If there is an example where the token gets refresh in the json file it will be helpful. I am using Laravel FW.

Thanks

kunallibra commented 3 years ago

how can I get the access tokens etc... so that i can save it programmatically in the database @anchordigi

Can you point to some code or help with some code please, really appriciate.

Thanks

SidneyAllen commented 3 years ago

@kunallibra - I'm sorry but support for how to programmatically persist data in a database is beyond the scope of this project.

There are lots of youtube videos, tutorials and even online courses that may help you learn how to do this securely. I can't recommend where to go next, but there are many options.