Version010401Date20181207190718.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\OAuth2\Migration;
  25. use Closure;
  26. use OCP\DB\ISchemaWrapper;
  27. use OCP\Migration\SimpleMigrationStep;
  28. use OCP\Migration\IOutput;
  29. class Version010401Date20181207190718 extends SimpleMigrationStep {
  30. /**
  31. * @param IOutput $output
  32. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  33. * @param array $options
  34. * @return null|ISchemaWrapper
  35. */
  36. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  37. /** @var ISchemaWrapper $schema */
  38. $schema = $schemaClosure();
  39. if (!$schema->hasTable('oauth2_clients')) {
  40. $table = $schema->createTable('oauth2_clients');
  41. $table->addColumn('id', 'integer', [
  42. 'autoincrement' => true,
  43. 'notnull' => true,
  44. 'unsigned' => true,
  45. ]);
  46. $table->addColumn('name', 'string', [
  47. 'notnull' => true,
  48. 'length' => 64,
  49. ]);
  50. $table->addColumn('redirect_uri', 'string', [
  51. 'notnull' => true,
  52. 'length' => 2000,
  53. ]);
  54. $table->addColumn('client_identifier', 'string', [
  55. 'notnull' => true,
  56. 'length' => 64,
  57. ]);
  58. $table->addColumn('secret', 'string', [
  59. 'notnull' => true,
  60. 'length' => 64,
  61. ]);
  62. $table->setPrimaryKey(['id']);
  63. $table->addIndex(['client_identifier'], 'oauth2_client_id_idx');
  64. }
  65. if (!$schema->hasTable('oauth2_access_tokens')) {
  66. $table = $schema->createTable('oauth2_access_tokens');
  67. $table->addColumn('id', 'integer', [
  68. 'autoincrement' => true,
  69. 'notnull' => true,
  70. 'unsigned' => true,
  71. ]);
  72. $table->addColumn('token_id', 'integer', [
  73. 'notnull' => true,
  74. ]);
  75. $table->addColumn('client_id', 'integer', [
  76. 'notnull' => true,
  77. ]);
  78. $table->addColumn('hashed_code', 'string', [
  79. 'notnull' => true,
  80. 'length' => 128,
  81. ]);
  82. $table->addColumn('encrypted_token', 'string', [
  83. 'notnull' => true,
  84. 'length' => 786,
  85. ]);
  86. $table->setPrimaryKey(['id']);
  87. $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
  88. $table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
  89. }
  90. return $schema;
  91. }
  92. }