Pricing Blog

Getting refresh tokens to work via http cookie

  • izma667-1396955321976623286

    izma

    3 months ago

    Hi everyone, been struggling with this for a while and and can't quite understand why it doesn't work. Couldn't find any solid answers though this question has come up before. IMO, this should be an easy thing to accomplish, as it's such a common use case:

    Issue
    I can't get the refresh tokens to send in the API call.

    What I've tried
    - During the login step, the Directus backend API returns a access_token and a refresh_token
    - I set a Http-Only Cookie for the refresh_token and a session_cookie for the access_token
    - The user gets redirected to the next page, on load a refresh token workflow is called that has an interval which makes a Token Refresh call to the Directus API, sending the previously stored Http-Only Cookie in the body
    - Despite the inject cookies in body setting, the http cookie is not properly included into the body
    - The issue is clearly visible in the Payload body that's sent
    - Though I can see that the cookie is properly stored

    Expected behaviour
    - To have a way to access Http-only cookie values and pass them to API calls

    Thanks in advance.
    1396955322484002867-image.png
    1396955323209613322-image.png
    1396955325487251637-image.png
    1396955325956886538-image.png
    1
  • lucasg-1396956158589403318

    Lucas G

    3 months ago

    You won't see the actual value on the console call, it gets replaced when the proxy handles it
  • lucasg-1396956435786498162

    Lucas G

    3 months ago

    You may also need to set an expiry value
  • izma667-1396961870015107163

    izma

    3 months ago

    Bingo! Thank you @Lucas G !

    To anyone who might run into the same issue in the future:
    - If your API returns an Expires in value, set it for both Http-Only Cookie and Session Cookie.
    - The setting I had marked in the Advanced API settings is the correct setting to expose Http-Only Cookies to Payload body and it works as it should. Validated it via a debug webhook.
    1396961869532627044-image.png
    1396961869796741324-image.png
    👍1