Problem/Motivation

RefreshTokenEntityNormalizer::normalize() returns only value and expire. Access tokens and auth codes go through TokenEntityNormalizer, which also sets client. Refresh tokens don't, so every refresh_token row has an empty client field.

As a result, nothing can find refresh tokens by client:

  • ExpiredCollector::collectForClient($client, TRUE) never returns refresh tokens, even though $include_refresh exists for exactly that.
  • Deleting a consumer, or any cleanup keyed on the client, leaves its refresh tokens behind.

Steps to reproduce

  1. Complete an authorization code flow for a consumer with the refresh_token grant.
  2. Load the new oauth2_token entity with bundle refresh_token.
  3. $token->get('client')->isEmpty() is TRUE.
  4. \Drupal::service('simple_oauth.expired_collector')->collectForClient($consumer, TRUE) returns only the access token.

Proposed resolution

Set client in RefreshTokenEntityNormalizer::normalize() from the access token the refresh token belongs to:

$client = $token_entity->getAccessToken()->getClient();
assert($client instanceof ClientEntityInterface);
return [
  'client' => ['target_id' => $client->getDrupalEntity()->id()],
  'value' => $token_entity->getIdentifier(),
  'expire' => $token_entity->getExpiryDateTime()->format('U'),
];

Existing refresh tokens can't be backfilled, because the row has no link to its access token. They expire on their own (the default is 14 days).

Remaining tasks

  • MR with a kernel test asserting collectForClient($client, TRUE) returns the refresh token.

Data model changes

None. The client field already exists on every bundle.

AI disclosure

AI-Generated: Yes. I drafted this issue summary with Claude Code and reviewed it before filing.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
attilatilman’s picture

Status: Needs review » Reviewed & tested by the community
vidit.anjaria’s picture

bojan_dev made their first commit to this issue’s fork.

  • bojan_dev committed 7549aec1 on 6.1.x authored by mglaman
    fix: #3630881 Store the client on refresh tokens
    
    By: mglaman
    By:...
bojan_dev’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, rebased and merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.