Topic:   How to store token in cache in rest api?
Nov 06, 2020 02:47 10 Replies 543 Views DIVYA

 How to store token in cache in rest api?

Prev Next
Topic Replies (10)
  1. 1
    idnkx user

    SAI

    Use cookies to securely store stuff you must use `httpOnly` cookies. But access token don't net to be stored anywhere.

    1
    idnkx user

    ANANYA

    It's against rest api principles, the client should store the token and send it inside every api call

    1
    idnkx user

    SWEETY

    i agree! learn more about token interception in frontend

    1
    idnkx user

    PADMAKEECHU

    No need to store token in cashe just create singleton class with method which wil return the token and call it after login

    1
    idnkx user

    TEJA

    Indeed. A singleton and resend in a bearer header on every call.

    1
    idnkx user

    TEJA

    could you please share any blog or reference ? Thanks.

    1
    idnkx user

    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.

    1
    idnkx user

    ALLINO

    Search for MemoryCache

    1
    idnkx user

    SAI

    Use coding.Use Redis Cache

    1
    idnkx user

    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..

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.


Let`s Connect