Making refresh tokens optional

Author: xiehanCreated Aug 31, 2016Updated Dec 22, 2025
LabelsImprovement Idea

I'm working through the V4->V5 upgrade (we're using Diactoros to work around the PSR-7 requirement for now) and one thing that has me stumped is how to make refresh tokens optional. This was very easy to do in V4, but it isn't clear to me how to do it in V5.

I realize it's a good idea to use them (not using them when we first implemented OAuth using V4 has bitten us in a number of ways) and we're in the process of migrating our existing production clients to use them, but not all of them are ready for that transition yet, and we're contractually obligated to respect that.

Looking at how RefreshTokenRepository is set up, I originally thought I could just have getNewRefreshToken return null, but that breaks everything in AbstractGrant::issueRefreshToken(). I suppose I could just have persistNewRefreshToken not do anything (i.e. not actually save the token to the database), but the token will still get included in the response, which we're trying to avoid because it could potentially break a client application that isn't expecting that field to be in the response (or, conversely, someone using a standard OAuth client that can parse it, and that then may try to use a refresh token that was never saved to the database).

Any guidance? Am I missing something?

Source: thephpleague/oauth2-server