Реализована логика oAuth авторизации приложений, добавлен Redis, удалены лишние тесты, пофикшены старые.

This commit is contained in:
ErickSkrauch
2016-02-14 20:50:10 +03:00
parent 59addfac07
commit f5f93ddef1
52 changed files with 1752 additions and 317 deletions

View File

@@ -11,11 +11,34 @@ class Migration extends YiiMigration {
public function getTableOptions($engine = 'InnoDB') {
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=' . $engine;
}
return $tableOptions;
}
protected function primary(...$columns) {
switch (count($columns)) {
case 0:
$key = '';
break;
case 1:
$key = $columns[0];
break;
default:
$key = $this->buildKey($columns);
}
return " PRIMARY KEY ($key) ";
}
private function buildKey(array $columns) {
$key = '';
foreach ($columns as $i => $column) {
$key .= $i == count($columns) ? $column : "$column,";
}
return $key;
}
}

View File

@@ -0,0 +1,77 @@
<?php
use console\db\Migration;
class m160201_055928_oauth extends Migration {
public function safeUp() {
$this->createTable('{{%oauth_clients}}', [
'id' => $this->string(64),
'secret' => $this->string()->notNull(),
'name' => $this->string()->notNull(),
'description' => $this->string(),
'redirect_uri' => $this->string()->notNull(),
'account_id' => $this->getDb()->getTableSchema('{{%accounts}}')->getColumn('id')->dbType,
'is_trusted' => $this->boolean()->defaultValue(false)->notNull(),
'created_at' => $this->integer()->notNull(),
$this->primary('id'),
], $this->tableOptions);
$this->createTable('{{%oauth_scopes}}', [
'id' => $this->string(64),
$this->primary('id'),
], $this->tableOptions);
$this->createTable('{{%oauth_sessions}}', [
'id' => $this->primaryKey(),
'owner_type' => $this->string()->notNull(),
'owner_id' => $this->string()->notNull(),
'client_id' => $this->getDb()->getTableSchema('{{%oauth_clients}}')->getColumn('id')->dbType,
'client_redirect_uri' => $this->string(),
], $this->tableOptions);
$this->createTable('{{%oauth_access_tokens}}', [
'access_token' => $this->string(64),
'session_id' => $this->getDb()->getTableSchema('{{%oauth_sessions}}')->getColumn('id')->dbType,
'expire_time' => $this->integer()->notNull(),
$this->primary('access_token'),
], $this->tableOptions);
$this->addForeignKey(
'FK_oauth_client_to_accounts',
'{{%oauth_clients}}',
'account_id',
'{{%accounts}}',
'id',
'CASCADE'
);
$this->addForeignKey(
'FK_oauth_session_to_client',
'{{%oauth_sessions}}',
'client_id',
'{{%oauth_clients}}',
'id',
'CASCADE',
'CASCADE'
);
$this->addForeignKey(
'FK_oauth_access_toke_to_oauth_session',
'{{%oauth_access_tokens}}',
'session_id',
'{{%oauth_sessions}}',
'id',
'CASCADE',
'SET NULL'
);
}
public function safeDown() {
$this->dropTable('{{%oauth_access_tokens}}');
$this->dropTable('{{%oauth_sessions}}');
$this->dropTable('{{%oauth_scopes}}');
$this->dropTable('{{%oauth_clients}}');
}
}