2

I am creating a rest template to consume REST API secured by OAuth 2.0.

The provider has implemented an expiry for the access token for 5 mins. So Using the rest template, I will be calling the database and sending records via Rest Template.

The records may vary from 10k to 1 million, so I wanted to create a fault proof system. In the process of sending records even if the token expires, I should be sending the records to the server.

What is the best way of achieving this?

Any help or inputs are highly appreciated.

2
  • Mark what you have sent and if token expires start from scratch but skip the records that already were sent.
    – bobek
    Commented Mar 9, 2020 at 20:42
  • At any point authentication fails, and given that OAUTH2 has been set up to spec, there should be a refresh token available for you to re-auth quickly and just carry on with a fresh token. Commented Apr 8, 2020 at 21:24

1 Answer 1

1

Authentication and authorization are typically checked while handling a request. Unless you have specific requirements specifying that you must do something more, keep it simple. Trying to do this kind of check during the response processing is going to really increase the complexity of the API.

Remember that there's nothing magical about the 300 seconds. The point of having a short time-out on tokens is to prevent attackers from scavenging old tokens and using them.

Again, your requirements could specify otherwise but if they don't, it's a standard assumption that you are only checking for this when handling the request, not during the handling of the response.

3
  • Thanks for your answer. But the whole process I have mentioned in my post is all about data sync between two systems and mostly synchronizing two systems and keeping the data upto date in both the databases Commented Mar 9, 2020 at 22:58
  • @SantosshKumhar I don't see how that changes anything. Can you elaborate?
    – JimmyJames
    Commented Mar 10, 2020 at 13:47
  • @SantosshKumhar I would also suggest that when you are authenticating two systems that you consider using mutual TLS (mTLS) instead. It's hard to say without knowing more about your requirements.
    – JimmyJames
    Commented Mar 10, 2020 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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