mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Remove refresh_token from OAuth2 result. Return the same access_token as a refresh_token in case when it's requested. Make access_tokens to live forever.
This commit is contained in:
		| @@ -41,7 +41,6 @@ use const common\LATEST_RULES_VERSION; | ||||
|  * @property UsernameHistory[]    $usernameHistory | ||||
|  * @property AccountSession[]     $sessions | ||||
|  * @property MinecraftAccessKey[] $minecraftAccessKeys | ||||
|  * @property-read OauthRefreshToken[] $oauthRefreshTokens | ||||
|  * | ||||
|  * Behaviors: | ||||
|  * @mixin TimestampBehavior | ||||
| @@ -102,10 +101,6 @@ class Account extends ActiveRecord { | ||||
|         return $this->hasMany(OauthClient::class, ['account_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public function getOauthRefreshTokens(): ActiveQuery { | ||||
|         return $this->hasMany(OauthRefreshToken::class, ['account_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public function getUsernameHistory(): ActiveQuery { | ||||
|         return $this->hasMany(UsernameHistory::class, ['account_id' => 'id']); | ||||
|     } | ||||
|   | ||||
| @@ -26,7 +26,6 @@ use yii\db\ActiveRecord; | ||||
|  * Behaviors: | ||||
|  * @property Account|null $account | ||||
|  * @property OauthSession[] $sessions | ||||
|  * @property-read OauthRefreshToken[] $refreshTokens | ||||
|  */ | ||||
| class OauthClient extends ActiveRecord { | ||||
|  | ||||
| @@ -58,10 +57,6 @@ class OauthClient extends ActiveRecord { | ||||
|         return $this->hasMany(OauthSession::class, ['client_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public function getRefreshTokens(): ActiveQuery { | ||||
|         return $this->hasMany(OauthRefreshToken::class, ['client_id' => 'id']); | ||||
|     } | ||||
|  | ||||
|     public static function find(): OauthClientQuery { | ||||
|         return Yii::createObject(OauthClientQuery::class, [static::class]); | ||||
|     } | ||||
|   | ||||
| @@ -1,50 +0,0 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace common\models; | ||||
|  | ||||
| use yii\behaviors\TimestampBehavior; | ||||
| use yii\db\ActiveQuery; | ||||
| use yii\db\ActiveRecord; | ||||
|  | ||||
| /** | ||||
|  * Fields: | ||||
|  * @property string $id | ||||
|  * @property int    $account_id | ||||
|  * @property int    $client_id | ||||
|  * @property int    $issued_at | ||||
|  * | ||||
|  * Relations: | ||||
|  * @property-read OauthSession $session | ||||
|  * @property-read Account $account | ||||
|  * @property-read OauthClient $client | ||||
|  */ | ||||
| class OauthRefreshToken extends ActiveRecord { | ||||
|  | ||||
|     public static function tableName(): string { | ||||
|         return 'oauth_refresh_tokens'; | ||||
|     } | ||||
|  | ||||
|     public function behaviors(): array { | ||||
|         return [ | ||||
|             [ | ||||
|                 'class' => TimestampBehavior::class, | ||||
|                 'createdAtAttribute' => 'issued_at', | ||||
|                 'updatedAtAttribute' => false, | ||||
|             ], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function getSession(): ActiveQuery { | ||||
|         return $this->hasOne(OauthSession::class, ['account_id' => 'account_id', 'client_id' => 'client_id']); | ||||
|     } | ||||
|  | ||||
|     public function getAccount(): ActiveQuery { | ||||
|         return $this->hasOne(Account::class, ['id' => 'account_id']); | ||||
|     } | ||||
|  | ||||
|     public function getClient(): ActiveQuery { | ||||
|         return $this->hasOne(OauthClient::class, ['id' => 'client_id']); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -19,7 +19,6 @@ use yii\db\ActiveRecord; | ||||
|  * Relations: | ||||
|  * @property-read OauthClient $client | ||||
|  * @property-read Account $account | ||||
|  * @property-read OauthRefreshToken[] $refreshTokens | ||||
|  */ | ||||
| class OauthSession extends ActiveRecord { | ||||
|  | ||||
| @@ -44,10 +43,6 @@ class OauthSession extends ActiveRecord { | ||||
|         return $this->hasOne(Account::class, ['id' => 'owner_id']); | ||||
|     } | ||||
|  | ||||
|     public function getRefreshTokens(): ActiveQuery { | ||||
|         return $this->hasMany(OauthRefreshToken::class, ['account_id' => 'account_id', 'client_id' => 'client_id']); | ||||
|     } | ||||
|  | ||||
|     public function getScopes(): array { | ||||
|         if (empty($this->scopes) && $this->legacy_id !== null) { | ||||
|             return Yii::$app->redis->smembers($this->getLegacyRedisScopesKey()); | ||||
|   | ||||
| @@ -55,7 +55,6 @@ class FixtureHelper extends Module { | ||||
|             'legacyOauthSessionsScopes' => fixtures\LegacyOauthSessionScopeFixtures::class, | ||||
|             'legacyOauthAccessTokens' => fixtures\LegacyOauthAccessTokenFixture::class, | ||||
|             'legacyOauthAccessTokensScopes' => fixtures\LegacyOauthAccessTokenScopeFixture::class, | ||||
|             'oauthRefreshTokens' => fixtures\OauthRefreshTokensFixture::class, | ||||
|             'legacyOauthRefreshTokens' => fixtures\LegacyOauthRefreshTokenFixture::class, | ||||
|             'minecraftAccessKeys' => fixtures\MinecraftAccessKeyFixture::class, | ||||
|         ]; | ||||
|   | ||||
| @@ -1,19 +0,0 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace common\tests\fixtures; | ||||
|  | ||||
| use common\models\OauthRefreshToken; | ||||
| use yii\test\ActiveFixture; | ||||
|  | ||||
| class OauthRefreshTokensFixture extends ActiveFixture { | ||||
|  | ||||
|     public $modelClass = OauthRefreshToken::class; | ||||
|  | ||||
|     public $dataFile = '@root/common/tests/fixtures/data/oauth-refresh-tokens.php'; | ||||
|  | ||||
|     public $depends = [ | ||||
|         OauthSessionFixture::class, | ||||
|     ]; | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user