Not able to set the token expire time

Created on 4 July 2025, 6 days ago

Problem/Motivation

Iโ€™ve created a custom plugin programmatically that successfully returns an access token, but the resulting token object doesnโ€™t include the expiration time or the refresh token.

Here is the token information:

 League\OAuth2\Client\Token\AccessToken {#5504
  #accessToken: "longtokenstring"
  #expires: null
  #refreshToken: null
  #resourceOwnerId: null
  #values: []
}

Plugin code


namespace Drupal\fmp_api\Plugin\Oauth2Client;

use Drupal\oauth2_client\Plugin\Oauth2Client\Oauth2ClientPluginBase;
use Drupal\oauth2_client\Plugin\Oauth2Client\StateTokenStorage;

/**
 * Auth code with access example.
 *
 * @Oauth2Client(
 *   id = "marketing_auth_code",
 *   name = @Translation("Marketing Auth code"),
 *   grant_type = "client_credentials",
 *   token_uri = "https://www.api.com/getToken",
 *   scopes = {"read"},
 *   success_message = TRUE
 * )
 *
 * @SuppressWarnings(PHPMD)
 */
class MarketingAuthCode extends Oauth2ClientPluginBase {

  use StateTokenStorage;
}

Steps to reproduce

Enable the module,
Create a plugin programmatically and generate a token using that plugin.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

4.1

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia keshavv India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024