Forever sessions

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsForever sessions

This tutorial builds on the concepts covered in the other User Authentication tutorials. JWT session tokens can only be refreshed prior to the DF_JWT_REFRESH_TTL timer expiring. Normally when you refresh a JWT session token you get a new token but your refresh ttl window stays the same. It does not reset. Eventually when you will go outside this refresh ttl window you can no longer refresh your old token for a new one. You will have re-authenticate in order to obtain a brand new token.

However, when you use a forever session, every time you refresh your token the system also resets the refresh ttl window. This means that the refresh ttl window starts fresh when you get the new token. This will allow you to refresh your token forever as long as you refresh it within the refresh ttl window (which keeps extending as you refresh). ONCE THE REFRESH TTL WINDOW IS PASSED NO TOKEN CAN EVER BE REFRESHED. YOU WILL NEED TO RE-AUTHENTICATE AT THIS POINT.


To set up forever sessions, configure DF_ALLOW_FOREVER_SESSIONS and DF_JWT_TTL in the .env file. Note that DF_JWT_REFRESH_TTL will reset upon refreshing a forever token when DF_ALLOW_FOREVER_SESSIONS is set to true.

The .env file for a DreamFactory instance is located at the installation's root directory. Refer to the example .env-dist file provided in the GitHub repository here.


In .env, add or un-comment this line and set the value to true:


To make sure forever session is enabled, make the following API call.

GET http://{url}/api/v2/system/environment

Look for the following in your response.



In .env, add or un-comment this line and set the value to your desired TTL in minutes. A session refresh will be required to receive a new session token after this many minutes.


The above setting will require a session refresh every 12 hours (720 minutes).

3. Clear config

Run this command from the root directory for your DreamFactory instance installation.

php artisan config:clear


  • A forever session is instantiated if the client sets "remember_me": true at login.
  • Forever sessions may be refreshed to receive a new session token at any time as long as the DF_JWT_REFRESH_TTL timer doesn't expire.
  • If a session is deleted or the refresh ttl is expired, the token can no longer be refreshed. Logging in again with valid credentials will be required.