Version010401Date20181207190718.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\IOutput;
  28. use OCP\Migration\SimpleMigrationStep;
  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. }