My CI app makes API call to third party Rest API server which will be consumed by the front end. At first, front end app will hit my CI app and which in turn will hit the third party LogInAPI
(session valid for 15 mins), and after login, we need to hit subsequent API calls by passing the key(response of loginApi
) in the header. So basically I need to hit loginAPI
for every 15 minutes. I am trying angular promise kinda approach in my Codeigniter app don't know how to achieve it? what is the best way to do it to prevent the front end from receiving empty or session expired response?
You do not need to keep refreshing that login. Create time stamp when You receive login from 3rd party API. Then pass it to back end on each request.
On the back end on each call from front end check time stamp, if it's expired do not do normal calls to API but first get the new login, then do requested calls.
As response to each front end call return also login info, so that front end gets's new credentials after renewal.
If credentials are app wide, then front end does not have to be aware of them at all. Just store credentials in some kind of storage (SQL DB, key value store, etc.), and do auto renewals when appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With