If the focus is the refresh cycle then the session variable isn’t what will do it. That doesn’t account for all manner of reasons that it wouldn’t be available when needed. Most often, the access and refresh tokens, along with the expiration date of the access token, are stored in a database. Then, say every hour, run a script that reads this row and at the right time (say 20 hours in to be sure) run the refresh cycle and when successful, update the database row with the new set of access and refresh tokens and the new expiry.