Good example: https://blog.joaograssi.com/typed-httpclient-with.../ It doesn't illustrate a singleton, but it uses a messagehandler to "handle" all your token requirements. Also note that your token has a lifetime you can check so there is no need to get a new token on every call, hence the "caching". Also note that when you are working with tokens that there is a difference between JWTokens and Reference tokens where the latter is only a reference to the token payload in your datastore. The advantage of the latter is that you can "revoke" the token by simply deleting the token payload from your datastore. With a JWT once it is delivered, you cannot take it back and it is valid until its validity has run out.
U must use http secure cookies from the response, Easy ... store it in local storage pull it out to use it ... with every call send it to server .... jwt..
Leave a Reply
Guest User
Not sure what course is right for you?
Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.
SAI
Use cookies to securely store stuff you must use `httpOnly` cookies. But access token don't net to be stored anywhere.
ANANYA
It's against rest api principles, the client should store the token and send it inside every api call
SWEETY
i agree! learn more about token interception in frontend
PADMAKEECHU
No need to store token in cashe just create singleton class with method which wil return the token and call it after login
TEJA
Indeed. A singleton and resend in a bearer header on every call.
TEJA
could you please share any blog or reference ? Thanks.
SAI
Good example: https://blog.joaograssi.com/typed-httpclient-with.../ It doesn't illustrate a singleton, but it uses a messagehandler to "handle" all your token requirements. Also note that your token has a lifetime you can check so there is no need to get a new token on every call, hence the "caching". Also note that when you are working with tokens that there is a difference between JWTokens and Reference tokens where the latter is only a reference to the token payload in your datastore. The advantage of the latter is that you can "revoke" the token by simply deleting the token payload from your datastore. With a JWT once it is delivered, you cannot take it back and it is valid until its validity has run out.
ALLINO
Search for MemoryCache
SAI
Use coding.Use Redis Cache
SAI
U must use http secure cookies from the response, Easy ... store it in local storage pull it out to use it ... with every call send it to server .... jwt..