Add support for the legacy refresh tokens, make the new refresh tokens non-expire [skip ci]

This commit is contained in:
ErickSkrauch
2019-09-22 02:42:08 +03:00
parent 5536c34b9c
commit c722c46ad5
7 changed files with 94 additions and 66 deletions

View File

@@ -56,6 +56,20 @@ class OauthSession extends ActiveRecord {
return (array)$this->scopes;
}
/**
* In the early period of the project existence, the refresh tokens related to the current session
* were stored in Redis. This method allows to get a list of these tokens.
*
* @return array of refresh tokens (ids)
*/
public function getLegacyRefreshTokens(): array {
if ($this->legacy_id === null) {
return [];
}
return Yii::$app->redis->smembers($this->getLegacyRedisRefreshTokensKey());
}
public function beforeDelete(): bool {
if (!parent::beforeDelete()) {
return false;
@@ -63,6 +77,7 @@ class OauthSession extends ActiveRecord {
if ($this->legacy_id !== null) {
Yii::$app->redis->del($this->getLegacyRedisScopesKey());
Yii::$app->redis->del($this->getLegacyRedisRefreshTokensKey());
}
return true;
@@ -72,4 +87,8 @@ class OauthSession extends ActiveRecord {
return "oauth:sessions:{$this->legacy_id}:scopes";
}
private function getLegacyRedisRefreshTokensKey(): string {
return "oauth:sessions:{$this->legacy_id}:refresh:tokens";
}
}