Re-authorizing
Closed this issue · 2 comments
Thanks so much for this work - it is excellent. When I am developing with your ebay-api (using it in a docker container) I find myself having to re-authorise at eBay (eBay.OAuth2.generateAuthUrl()) every time I take the container down. I could persist the tokens so I can reuse them without going back to eBay. I get an access token (eBay.OAuth2.getToken) when I get this token I could persist it and re-use it I think.
My question is can I persist a token (I am usually rerunning the docker container within 30 minutes)? What token would I persist and what method in your api would I call with this token to maintain/re-establish the connection? Thanks again its the flow that is confusing me.
Gary
Hey Gary,
I would recommend to persist the token in a DB. You have options, like SQLite, MySQL/Postgres or MongoDB etc. These databeses are easy to setup (docker).
Initial Login:
// Get the initial token
const token = await eBay.OAuth2.getToken(code);
eBay.OAuth2.setCredentials(token);
// store the `token` in DB
await yourDb.persist('token', token)
Before using the API:
const token = await yourDb.get('token')
if (!token) {
// you have to sign in with eBay first
return
}
eBay.OAuth2.setCredentials(token);
// listen to refresh token event
eBay.OAuth2.on('refreshAuthToken', async (token) => {
await yourDb.persist('token', token)
});