Remove expires_in field when the access_token isn't expiring

This commit is contained in:
ErickSkrauch 2019-12-13 16:00:51 +03:00
parent 22d8971dc5
commit 40eca5b8b6
3 changed files with 11 additions and 7 deletions

View File

@ -176,11 +176,15 @@ class OauthProcess {
} }
if (($result['expires_in'] ?? 0) <= 0) { if (($result['expires_in'] ?? 0) <= 0) {
if ($shouldIssueRefreshToken || $grantType === 'refresh_token') {
// Since some of our clients use this field to understand how long the token will live, // Since some of our clients use this field to understand how long the token will live,
// we have to give it some value. The tokens with zero lifetime don't expire // we have to give it some value. The tokens with zero lifetime don't expire
// but in order not to break the clients storing the value as integer on 32-bit systems, // but in order not to break the clients storing the value as integer on 32-bit systems,
// let's calculate the value based on the unsigned maximum for this type // let's calculate the value based on the unsigned maximum for this type
$result['expires_in'] = 2 ** 31 - time(); $result['expires_in'] = 2 ** 31 - time();
} else {
unset($result['expires_in']);
}
} }
Yii::$app->statsd->inc("oauth.issueToken_client.{$clientId}"); Yii::$app->statsd->inc("oauth.issueToken_client.{$clientId}");

View File

@ -22,7 +22,7 @@ class AccessTokenCest {
'token_type' => 'Bearer', 'token_type' => 'Bearer',
]); ]);
$I->canSeeResponseJsonMatchesJsonPath('$.access_token'); $I->canSeeResponseJsonMatchesJsonPath('$.access_token');
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in'); $I->cantSeeResponseJsonMatchesJsonPath('$.expires_in');
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token'); $I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
} }

View File

@ -79,7 +79,7 @@ class ClientCredentialsCest {
'token_type' => 'Bearer', 'token_type' => 'Bearer',
]); ]);
$I->canSeeResponseJsonMatchesJsonPath('$.access_token'); $I->canSeeResponseJsonMatchesJsonPath('$.access_token');
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in'); $I->cantSeeResponseJsonMatchesJsonPath('$.expires_in');
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token'); $I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
} }