1

I am building a simple application built in Rails that allows the client to connect to a third party api to sync customer data.

The customer inputs their username and password and my application retrieves an OAuth access token which is valid for the current datetime + 24 hours.

My current theory is that I run a cron job every hour to check for tokens that are about to expire within the next hour. If there are any then I request a new token.

I wanted to validate this theory or be advised on any alternative approaches.

1 Answer 1

3

Before you use the token, check the expiry date and request a new token if required.

After you use the token, if you get a expired response, request a new token.

2
  • I agree that handling the error condition when the token is expired is rather elegant since it's solves two problems. Since the token make be invalidated for another reason other than time expiry, you need to handle the invalid token condition anyway.
    – tavis
    Sep 10, 2020 at 9:18
  • its best to check before send, but there are always edge cases where you might expire between sending and the server checking
    – Ewan
    Sep 10, 2020 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.