Reputation: 699
We're thinking about an architecture for our next app and we're having problems with pass the tokens between APIs. We'll have:
ownToken
) -->(call to) third party API --> returns a JWT token (named 1token
) -->After everything is ok :
ownToken
Call to) own business API (If ownToken
is ok, do some stuffs)--> (with the 1token
Call to) third party API (return some stuffs) --> Show information to the user.We want to avoid calling the third party API every time that we want information from that API, but also we don't want to show that JWT to the user (I mean localstorage, sessionstorage...).
For more information, we'll use C# language and SQL server as database.
Our question:
How do you maintain 1token
between APIs?
Upvotes: 0
Views: 488
Reputation: 2626
you have two different things which need to be managed:
What I would do is simply generate a 'sessionId' in the back-end which is part of the token you send to your front end. this could be an int or guid or whatever.
I would then associate this 'sessionId' with the token retrieved from the 3rd party and store that somehow - some form of database or file storage (DB would be the obvious thing to use).
That way whenever a request comes in from your front end in your back-end code you should:
You'd have to make sure to update this association whenever you need to get new tokens, but that shouldn't be too hard.
You could also use this to make the nature of the thing a bit more async - you could return immediately to your front end with a response suggesting it's 'Working On It' then the front end could call a separate endpoint later to get the results... That way if the 3rd party link takes a while then the original request isn't left waiting too long for a response...
Upvotes: 3