Increase active session time
# support
t
Hello, I'm wondering what are the steps to increase the duration of the session. Let me explain my issue : I have a mobile application that records a night of sleep, the patient starts the recording at the beginning of the night, and then doesn't touch the phone for the night (several hours). In the morning the patient clicks on a button to finish the Procedure. But at that point the access token is not working anymore, and from my understanding, the refresh token neither. Can you guide me on the steps to increase the session duration ? I'm on a self hosted AWS. Thank you.
For information after more tests, at the moment as soon as we have more than one hour without any request in our application, the refresh token is not useful anymore.
@rahul1 @reshma if you have any ideas here. Thanks
r
HI @thomabig , as a security best practice we we set access tokens to 1hr. However, refresh tokens are active for 2 weeks
For users who need long sessions, we recommend preemptively refereshing the token before it expires
The
refreshIfExpired
function allows you to fetch a new accessToken before the current one expires by specifying a grace period
Best practice for long-session workflows to call this on a timer
t
Thanks for your answer @rahul1 So just to be sure I can be inactive for two hours for example and then use the refreshToken to get a new token ? Can you please confirm that these timelines are correct ? I've been trying to understand everything through the code but that was not fully clear to me ! One thing that I did not fully understand is how do we verify case 4 ? Meaning when is it verified the the refresh_token is expired. The only code I saw where "time" is mentionned during the refresh token process is the following :
Copy code
// Use a timing-safe-equal here so that we don't expose timing information which could be
  // used to infer the secret value
  if (!timingSafeEqualStr(login.refreshSecret, claims.refresh_secret)) {
    sendTokenError(res, 'invalid_request', 'Invalid token');
    return;
  }
But I'm not sure what timingSafeEqualStr means. And not sure this is the piece of code that makes the refresh token not available anymore.
r
Hi @thomabig circling back here
Case 1 looks correct for me
Case 2 also works - the 5 min grace period means that the 8:56 call should refresh the token
Case 3 is right - after the access token expires, you can exchange the refresh token for a new access token
Case 4 is also right - after 2 weeks, the refresh token and access token are both expired. They relevant code is here: https://github.com/medplum/medplum/blob/eab9c11a443cb000cf37373c855561cd33c1d01e/packages/server/src/oauth/keys.ts#L239
t
Thank you 🙂
180 Views