mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Completely restored authorization_code grant for user side.
Reworked oauth_sessions table. Added extension to use MariaDB's JSON columns. Rewritten tests for authorization_code grant for client side. Deprecate some old shit. [skip ci]
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use console\db\Migration;
|
||||
|
||||
class m190914_181236_rework_oauth_sessions_table extends Migration {
|
||||
|
||||
public function safeUp() {
|
||||
$this->delete('oauth_sessions', ['NOT', ['owner_type' => 'user']]);
|
||||
$this->dropColumn('oauth_sessions', 'owner_type');
|
||||
$this->dropColumn('oauth_sessions', 'client_redirect_uri');
|
||||
$this->execute('
|
||||
DELETE os1
|
||||
FROM oauth_sessions os1,
|
||||
oauth_sessions os2
|
||||
WHERE os1.id > os2.id
|
||||
AND os1.owner_id = os2.owner_id
|
||||
AND os1.client_id = os2.client_id
|
||||
');
|
||||
$this->dropIndex('owner_id', 'oauth_sessions');
|
||||
$this->renameColumn('oauth_sessions', 'owner_id', 'account_id');
|
||||
$this->alterColumn('oauth_sessions', 'account_id', $this->db->getTableSchema('accounts')->getColumn('id')->dbType . ' NOT NULL');
|
||||
$this->alterColumn('oauth_sessions', 'client_id', $this->db->getTableSchema('oauth_clients')->getColumn('id')->dbType . ' NOT NULL');
|
||||
// Change type to be able to remove primary key
|
||||
$this->alterColumn('oauth_sessions', 'id', $this->integer(11)->unsigned()->after('client_id'));
|
||||
$this->dropPrimaryKey('PRIMARY', 'oauth_sessions');
|
||||
// Change type again to make column nullable
|
||||
$this->alterColumn('oauth_sessions', 'id', $this->integer(11)->unsigned()->after('client_id'));
|
||||
$this->renameColumn('oauth_sessions', 'id', 'legacy_id');
|
||||
$this->addPrimaryKey('id', 'oauth_sessions', ['account_id', 'client_id']);
|
||||
$this->dropForeignKey('FK_oauth_session_to_client', 'oauth_sessions');
|
||||
$this->dropIndex('FK_oauth_session_to_client', 'oauth_sessions');
|
||||
$this->addForeignKey('FK_oauth_session_to_account', 'oauth_sessions', 'account_id', 'accounts', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->addForeignKey('FK_oauth_session_to_oauth_client', 'oauth_sessions', 'client_id', 'oauth_clients', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->addColumn('oauth_sessions', 'scopes', $this->json()->toString('scopes') . ' AFTER `legacy_id`');
|
||||
}
|
||||
|
||||
public function safeDown() {
|
||||
$this->dropColumn('oauth_sessions', 'scopes');
|
||||
$this->dropForeignKey('FK_oauth_session_to_oauth_client', 'oauth_sessions');
|
||||
$this->dropForeignKey('FK_oauth_session_to_account', 'oauth_sessions');
|
||||
$this->dropIndex('FK_oauth_session_to_oauth_client', 'oauth_sessions');
|
||||
$this->dropPrimaryKey('PRIMARY', 'oauth_sessions');
|
||||
$this->delete('oauth_sessions', ['legacy_id' => null]);
|
||||
$this->alterColumn('oauth_sessions', 'legacy_id', $this->integer(11)->unsigned()->notNull()->append('AUTO_INCREMENT PRIMARY KEY FIRST'));
|
||||
$this->renameColumn('oauth_sessions', 'legacy_id', 'id');
|
||||
$this->alterColumn('oauth_sessions', 'client_id', $this->db->getTableSchema('oauth_clients')->getColumn('id')->dbType);
|
||||
$this->alterColumn('oauth_sessions', 'account_id', $this->string());
|
||||
$this->renameColumn('oauth_sessions', 'account_id', 'owner_id');
|
||||
$this->createIndex('owner_id', 'oauth_sessions', 'owner_id');
|
||||
$this->addColumn('oauth_sessions', 'owner_type', $this->string()->notNull()->after('id'));
|
||||
$this->update('oauth_sessions', ['owner_type' => 'user']);
|
||||
$this->addColumn('oauth_sessions', 'client_redirect_uri', $this->string()->after('client_id'));
|
||||
$this->addForeignKey('FK_oauth_session_to_client', 'oauth_sessions', 'client_id', 'oauth_clients', 'id', 'CASCADE', 'CASCADE');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user