osso 0.0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.buildkite/hooks/environment +9 -0
  3. data/.buildkite/hooks/pre-command +7 -0
  4. data/.buildkite/pipeline.yml +6 -0
  5. data/.buildkite/template.yml +5 -0
  6. data/.gitignore +10 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +81 -0
  9. data/CODE_OF_CONDUCT.md +130 -0
  10. data/Gemfile +18 -0
  11. data/Gemfile.lock +176 -0
  12. data/LICENSE +111 -0
  13. data/README.md +2 -0
  14. data/Rakefile +14 -0
  15. data/bin/console +8 -0
  16. data/bin/setup +8 -0
  17. data/config/database.yml +14 -0
  18. data/db/schema.rb +133 -0
  19. data/lib/osso.rb +11 -0
  20. data/lib/osso/Rakefile +13 -0
  21. data/lib/osso/db/migrate/20190909230109_enable_uuid.rb +7 -0
  22. data/lib/osso/db/migrate/20200328135750_create_users.rb +12 -0
  23. data/lib/osso/db/migrate/20200328143303_create_oauth_tables.rb +57 -0
  24. data/lib/osso/db/migrate/20200328143305_create_identity_providers.rb +12 -0
  25. data/lib/osso/db/migrate/20200411184535_add_provider_id_to_users.rb +7 -0
  26. data/lib/osso/db/migrate/20200411192645_create_enterprise_accounts.rb +15 -0
  27. data/lib/osso/db/migrate/20200413132407_add_oauth_clients.rb +13 -0
  28. data/lib/osso/db/migrate/20200413142511_create_authorization_codes.rb +15 -0
  29. data/lib/osso/db/migrate/20200413163451_create_access_tokens.rb +13 -0
  30. data/lib/osso/db/migrate/20200502120616_create_redirect_uris_and_drop_from_oauth_clients.rb +13 -0
  31. data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_accounts_and_identity_providers.rb +6 -0
  32. data/lib/osso/db/migrate/20200714223226_add_identity_provider_service_enum.rb +17 -0
  33. data/lib/osso/db/migrate/20200715154211_rename_idp_fields_on_identity_provider_to_sso.rb +6 -0
  34. data/lib/osso/db/migrate/20200715205801_add_name_to_enterprise_account.rb +5 -0
  35. data/lib/osso/graphql/mutation.rb +16 -0
  36. data/lib/osso/graphql/mutations.rb +12 -0
  37. data/lib/osso/graphql/mutations/base_mutation.rb +41 -0
  38. data/lib/osso/graphql/mutations/configure_identity_provider.rb +36 -0
  39. data/lib/osso/graphql/mutations/create_enterprise_account.rb +25 -0
  40. data/lib/osso/graphql/mutations/create_identity_provider.rb +30 -0
  41. data/lib/osso/graphql/mutations/set_identity_provider.rb +27 -0
  42. data/lib/osso/graphql/query.rb +25 -0
  43. data/lib/osso/graphql/resolvers.rb +12 -0
  44. data/lib/osso/graphql/resolvers/enterprise_account.rb +25 -0
  45. data/lib/osso/graphql/resolvers/enterprise_accounts.rb +17 -0
  46. data/lib/osso/graphql/resolvers/oauth_clients.rb +15 -0
  47. data/lib/osso/graphql/schema.rb +46 -0
  48. data/lib/osso/graphql/types.rb +15 -0
  49. data/lib/osso/graphql/types/base_enum.rb +10 -0
  50. data/lib/osso/graphql/types/base_input_object.rb +10 -0
  51. data/lib/osso/graphql/types/base_object.rb +12 -0
  52. data/lib/osso/graphql/types/enterprise_account.rb +33 -0
  53. data/lib/osso/graphql/types/identity_provider.rb +37 -0
  54. data/lib/osso/graphql/types/identity_provider_service.rb +12 -0
  55. data/lib/osso/graphql/types/oauth_client.rb +20 -0
  56. data/lib/osso/graphql/types/user.rb +17 -0
  57. data/lib/osso/helpers/auth.rb +71 -0
  58. data/lib/osso/helpers/helpers.rb +8 -0
  59. data/lib/osso/lib/app_config.rb +20 -0
  60. data/lib/osso/lib/oauth2_token.rb +38 -0
  61. data/lib/osso/lib/route_map.rb +28 -0
  62. data/lib/osso/models/access_token.rb +29 -0
  63. data/lib/osso/models/authorization_code.rb +14 -0
  64. data/lib/osso/models/enterprise_account.rb +28 -0
  65. data/lib/osso/models/identity_provider.rb +48 -0
  66. data/lib/osso/models/models.rb +16 -0
  67. data/lib/osso/models/oauth_client.rb +32 -0
  68. data/lib/osso/models/redirect_uri.rb +20 -0
  69. data/lib/osso/models/saml_provider.rb +49 -0
  70. data/lib/osso/models/saml_providers/azure_saml_provider.rb +22 -0
  71. data/lib/osso/models/saml_providers/okta_saml_provider.rb +23 -0
  72. data/lib/osso/models/user.rb +24 -0
  73. data/lib/osso/rake.rb +4 -0
  74. data/lib/osso/routes/admin.rb +41 -0
  75. data/lib/osso/routes/auth.rb +67 -0
  76. data/lib/osso/routes/oauth.rb +63 -0
  77. data/lib/osso/routes/routes.rb +10 -0
  78. data/lib/osso/routes/views/error.erb +1 -0
  79. data/lib/osso/routes/views/multiple_providers.erb +1 -0
  80. data/lib/osso/version.rb +5 -0
  81. data/lib/tasks/bootstrap.rake +16 -0
  82. data/osso-rb.gemspec +40 -0
  83. data/spec/factories/authorization_code.rb +10 -0
  84. data/spec/factories/enterprise_account.rb +46 -0
  85. data/spec/factories/identity_providers.rb +49 -0
  86. data/spec/factories/oauth_client.rb +12 -0
  87. data/spec/factories/redirect_uri.rb +14 -0
  88. data/spec/factories/user.rb +18 -0
  89. data/spec/graphql/mutations/configure_identity_provider_spec.rb +75 -0
  90. data/spec/graphql/mutations/create_enterprise_account_spec.rb +68 -0
  91. data/spec/graphql/mutations/create_identity_provider_spec.rb +104 -0
  92. data/spec/graphql/query/enterprise_account_spec.rb +68 -0
  93. data/spec/graphql/query/enterprise_accounts_spec.rb +44 -0
  94. data/spec/graphql/query/identity_provider_spec.rb +65 -0
  95. data/spec/graphql/query/oauth_clients_account_spec.rb +48 -0
  96. data/spec/models/azure_saml_provider_spec.rb +19 -0
  97. data/spec/models/identity_provider_spec.rb +17 -0
  98. data/spec/models/okta_saml_provider_spec.rb +20 -0
  99. data/spec/routes/admin_spec.rb +60 -0
  100. data/spec/routes/app_spec.rb +6 -0
  101. data/spec/routes/auth_spec.rb +112 -0
  102. data/spec/routes/oauth_spec.rb +134 -0
  103. data/spec/spec_helper.rb +68 -0
  104. data/spec/support/spec_app.rb +9 -0
  105. data/spec/support/views/admin.erb +5 -0
  106. metadata +348 -0
data/LICENSE ADDED
@@ -0,0 +1,111 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Samuel Bauch
6
+ Licensed Work: osso-rb
7
+ The Licensed Work is (c) 2020 Samuel Bauch.
8
+ Additional Use Grant: You may make use of the Licensed Work, provided that you do
9
+ not use the Licensed Work in a Single Sign On Management
10
+ Service.
11
+
12
+ A "Single Sign On Management Service" is an offering
13
+ (be it free or commercial) that uses the Licensed Work
14
+ to allow third parties (other than your employees and
15
+ contractors) to access the functionality of the
16
+ Licensed Work such that any fourth parties directly
17
+ benefit from the authentication, configuration, or
18
+ documentation features of the Licensed Work.
19
+
20
+ You thus may only use the Licensed Work in a manner
21
+ whereby parties who directly benefit from the
22
+ authentication, configuration, or documentation features
23
+ of the Licensed Work are yourself, your employees or
24
+ contractors, and your customers or partners.
25
+
26
+ Change Date: 2023-05-01
27
+
28
+ Change License: Apache License, Version 2.0
29
+
30
+ For information about alternative licensing arrangements for the Software,
31
+ contact: hello@enterprise-oss.dev
32
+
33
+ Notice
34
+
35
+ The Business Source License (this document, or the "License") is not an Open
36
+ Source license. However, the Licensed Work will eventually be made available
37
+ under an Open Source License, as stated in this License.
38
+
39
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
40
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
41
+
42
+ -----------------------------------------------------------------------------
43
+
44
+ Business Source License 1.1
45
+
46
+ Terms
47
+
48
+ The Licensor hereby grants you the right to copy, modify, create derivative
49
+ works, redistribute, and make non-production use of the Licensed Work. The
50
+ Licensor may make an Additional Use Grant, above, permitting limited
51
+ production use.
52
+
53
+ Effective on the Change Date, or the fourth anniversary of the first publicly
54
+ available distribution of a specific version of the Licensed Work under this
55
+ License, whichever comes first, the Licensor hereby grants you rights under
56
+ the terms of the Change License, and the rights granted in the paragraph
57
+ above terminate.
58
+
59
+ If your use of the Licensed Work does not comply with the requirements
60
+ currently in effect as described in this License, you must purchase a
61
+ commercial license from the Licensor, its affiliated entities, or authorized
62
+ resellers, or you must refrain from using the Licensed Work.
63
+
64
+ All copies of the original and modified Licensed Work, and derivative works
65
+ of the Licensed Work, are subject to this License. This License applies
66
+ separately for each version of the Licensed Work and the Change Date may vary
67
+ for each version of the Licensed Work released by Licensor.
68
+
69
+ You must conspicuously display this License on each original or modified copy
70
+ of the Licensed Work. If you receive the Licensed Work in original or
71
+ modified form from a third party, the terms and conditions set forth in this
72
+ License apply to your use of that work.
73
+
74
+ Any use of the Licensed Work in violation of this License will automatically
75
+ terminate your rights under this License for the current and all other
76
+ versions of the Licensed Work.
77
+
78
+ This License does not grant you any right in any trademark or logo of
79
+ Licensor or its affiliates (provided that you may use a trademark or logo of
80
+ Licensor as expressly required by this License).
81
+
82
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
83
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
84
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
85
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
86
+ TITLE.
87
+
88
+ MariaDB hereby grants you permission to use this License’s text to license
89
+ your works, and to refer to it using the trademark "Business Source License",
90
+ as long as you comply with the Covenants of Licensor below.
91
+
92
+ Covenants of Licensor
93
+
94
+ In consideration of the right to use this License’s text and the "Business
95
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
96
+ other recipients of the licensed work to be provided by Licensor:
97
+
98
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
99
+ or a license that is compatible with GPL Version 2.0 or a later version,
100
+ where "compatible" means that software provided under the Change License can
101
+ be included in a program with software provided under GPL Version 2.0 or a
102
+ later version. Licensor may specify additional Change Licenses without
103
+ limitation.
104
+
105
+ 2. To either: (a) specify an additional grant of rights to use that does not
106
+ impose any additional restriction on the right granted in this License, as
107
+ the Additional Use Grant; or (b) insert the text "None".
108
+
109
+ 3. To specify a Change Date.
110
+
111
+ 4. Not to modify this License in any other way.
@@ -0,0 +1,2 @@
1
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2b04828dc45bcb5abcb1/maintainability)](https://codeclimate.com/github/enterprise-oss/osso-rb/maintainability)
2
+ [![Build status](https://badge.buildkite.com/0e01845bdd51be4131b9cbd496d9caa39cd48f171fc2d9a9ca.svg)](https://buildkite.com/enterpriseoss/osso-rb)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This Rakefile is used in gem development in order
4
+ # to tell ActiveRecord where to find the database
5
+ # schema and migrations
6
+
7
+ require 'bundler/gem_tasks'
8
+ require 'sinatra/activerecord/rake'
9
+ require './lib/osso'
10
+
11
+ ActiveRecord::Migrator.migrations_paths = ['./lib/osso/db/migrate']
12
+ Dir.glob('lib/tasks/*.rake').each { |r| load r }
13
+
14
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'osso'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ development:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: 5
5
+ database: ossorb-development
6
+ host: ''
7
+ port: 5432
8
+ test:
9
+ adapter: postgresql
10
+ encoding: unicode
11
+ pool: 5
12
+ database: ossorb-test
13
+ host: ''
14
+ port: 5432
@@ -0,0 +1,133 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2020_07_15_205801) do
14
+
15
+ # These are extensions that must be enabled in order to support this database
16
+ enable_extension "pgcrypto"
17
+ enable_extension "plpgsql"
18
+
19
+ create_table "access_tokens", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
20
+ t.string "token"
21
+ t.datetime "expires_at"
22
+ t.datetime "created_at", precision: 6, null: false
23
+ t.datetime "updated_at", precision: 6, null: false
24
+ t.uuid "user_id"
25
+ t.uuid "oauth_client_id"
26
+ t.index ["oauth_client_id"], name: "index_access_tokens_on_oauth_client_id"
27
+ t.index ["user_id"], name: "index_access_tokens_on_user_id"
28
+ end
29
+
30
+ create_table "authorization_codes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
31
+ t.string "token"
32
+ t.string "redirect_uri"
33
+ t.datetime "expires_at"
34
+ t.datetime "created_at", precision: 6, null: false
35
+ t.datetime "updated_at", precision: 6, null: false
36
+ t.uuid "user_id"
37
+ t.uuid "oauth_client_id"
38
+ t.index ["oauth_client_id"], name: "index_authorization_codes_on_oauth_client_id"
39
+ t.index ["token"], name: "index_authorization_codes_on_token", unique: true
40
+ t.index ["user_id"], name: "index_authorization_codes_on_user_id"
41
+ end
42
+
43
+ create_table "enterprise_accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
44
+ t.string "domain", null: false
45
+ t.uuid "external_uuid"
46
+ t.integer "external_int_id"
47
+ t.string "external_id"
48
+ t.uuid "oauth_client_id"
49
+ t.string "name", null: false
50
+ t.index ["domain"], name: "index_enterprise_accounts_on_domain", unique: true
51
+ t.index ["oauth_client_id"], name: "index_enterprise_accounts_on_oauth_client_id"
52
+ end
53
+
54
+ create_table "identity_providers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
55
+ t.string "service"
56
+ t.string "domain", null: false
57
+ t.string "sso_url"
58
+ t.text "sso_cert"
59
+ t.uuid "enterprise_account_id"
60
+ t.uuid "oauth_client_id"
61
+ t.index ["domain"], name: "index_identity_providers_on_domain"
62
+ t.index ["enterprise_account_id"], name: "index_identity_providers_on_enterprise_account_id"
63
+ t.index ["oauth_client_id"], name: "index_identity_providers_on_oauth_client_id"
64
+ end
65
+
66
+ create_table "oauth_access_grants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
67
+ t.uuid "resource_owner_id", null: false
68
+ t.uuid "application_id", null: false
69
+ t.string "token", null: false
70
+ t.integer "expires_in", null: false
71
+ t.text "redirect_uri", null: false
72
+ t.datetime "created_at", null: false
73
+ t.datetime "revoked_at"
74
+ t.string "scopes", default: "", null: false
75
+ t.index ["application_id"], name: "index_oauth_access_grants_on_application_id"
76
+ t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
77
+ end
78
+
79
+ create_table "oauth_access_tokens", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
80
+ t.uuid "resource_owner_id"
81
+ t.uuid "application_id"
82
+ t.string "token", null: false
83
+ t.string "refresh_token"
84
+ t.integer "expires_in"
85
+ t.datetime "revoked_at"
86
+ t.datetime "created_at", null: false
87
+ t.string "scopes"
88
+ t.string "previous_refresh_token", default: "", null: false
89
+ t.index ["application_id"], name: "index_oauth_access_tokens_on_application_id"
90
+ t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
91
+ t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
92
+ end
93
+
94
+ create_table "oauth_applications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
95
+ t.string "name", null: false
96
+ t.string "secret", null: false
97
+ t.text "redirect_uri", null: false
98
+ t.string "scopes", default: "", null: false
99
+ t.boolean "confidential", default: true, null: false
100
+ t.datetime "created_at", precision: 6, null: false
101
+ t.datetime "updated_at", precision: 6, null: false
102
+ end
103
+
104
+ create_table "oauth_clients", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
105
+ t.string "name", null: false
106
+ t.string "secret", null: false
107
+ t.string "identifier", null: false
108
+ t.index ["identifier"], name: "index_oauth_clients_on_identifier", unique: true
109
+ end
110
+
111
+ create_table "redirect_uris", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
112
+ t.string "uri", null: false
113
+ t.boolean "primary", default: false, null: false
114
+ t.uuid "oauth_client_id"
115
+ t.index ["oauth_client_id"], name: "index_redirect_uris_on_oauth_client_id"
116
+ t.index ["uri", "primary"], name: "index_redirect_uris_on_uri_and_primary", unique: true
117
+ end
118
+
119
+ create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
120
+ t.string "email", null: false
121
+ t.string "idp_id", null: false
122
+ t.uuid "identity_provider_id"
123
+ t.uuid "enterprise_account_id"
124
+ t.index ["email", "idp_id"], name: "index_users_on_email_and_idp_id", unique: true
125
+ t.index ["enterprise_account_id"], name: "index_users_on_enterprise_account_id"
126
+ end
127
+
128
+ add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
129
+ add_foreign_key "oauth_access_grants", "users", column: "resource_owner_id"
130
+ add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
131
+ add_foreign_key "oauth_access_tokens", "users", column: "resource_owner_id"
132
+ add_foreign_key "users", "identity_providers"
133
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Osso
4
+ require_relative 'osso/helpers/helpers'
5
+ require_relative 'osso/lib/app_config'
6
+ require_relative 'osso/lib/oauth2_token'
7
+ require_relative 'osso/lib/route_map'
8
+ require_relative 'osso/models/models'
9
+ require_relative 'osso/routes/routes'
10
+ require_relative 'osso/graphql/schema'
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'osso'
4
+
5
+ path = File.expand_path(__dir__)
6
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| import f }
7
+
8
+ namespace :db do
9
+ task :load_config do
10
+ osso_migrations = File.expand_path('./db/migrate', __dir__)
11
+ ActiveRecord::Migrator.migrations_paths << osso_migrations
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EnableUuid < ActiveRecord::Migration[6.0]
4
+ def change
5
+ enable_extension 'pgcrypto'
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateUsers < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :users, id: :uuid do |t|
6
+ t.string :email, null: false
7
+ t.string :idp_id, null: false
8
+ end
9
+
10
+ add_index :users, %i[email idp_id], unique: true
11
+ end
12
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateOauthTables < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :oauth_applications, id: :uuid do |t|
6
+ t.string :name, null: false
7
+ t.string :secret, null: false
8
+ t.text :redirect_uri, null: false
9
+ t.string :scopes, null: false, default: ''
10
+ t.boolean :confidential, null: false, default: true
11
+ t.timestamps null: false
12
+ end
13
+
14
+ create_table :oauth_access_grants, id: :uuid do |t|
15
+ t.uuid :resource_owner_id, null: false
16
+ t.references :application, type: :uuid, null: false
17
+ t.string :token, null: false
18
+ t.integer :expires_in, null: false
19
+ t.text :redirect_uri, null: false
20
+ t.datetime :created_at, null: false
21
+ t.datetime :revoked_at
22
+ t.string :scopes, null: false, default: ''
23
+ end
24
+
25
+ add_index :oauth_access_grants, :token, unique: true
26
+ add_foreign_key(
27
+ :oauth_access_grants,
28
+ :oauth_applications,
29
+ column: :application_id
30
+ )
31
+
32
+ create_table :oauth_access_tokens, id: :uuid do |t|
33
+ t.uuid :resource_owner_id
34
+ t.references :application, type: :uuid
35
+ t.string :token, null: false
36
+
37
+ t.string :refresh_token
38
+ t.integer :expires_in
39
+ t.datetime :revoked_at
40
+ t.datetime :created_at, null: false
41
+ t.string :scopes
42
+
43
+ t.string :previous_refresh_token, null: false, default: ''
44
+ end
45
+
46
+ add_index :oauth_access_tokens, :token, unique: true
47
+ add_index :oauth_access_tokens, :refresh_token, unique: true
48
+ add_foreign_key(
49
+ :oauth_access_tokens,
50
+ :oauth_applications,
51
+ column: :application_id
52
+ )
53
+
54
+ add_foreign_key :oauth_access_grants, :users, column: :resource_owner_id
55
+ add_foreign_key :oauth_access_tokens, :users, column: :resource_owner_id
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ class CreateIdentityProviders < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :identity_providers, id: :uuid do |t|
4
+ t.string :service
5
+ t.string :domain, null: false
6
+ t.string :idp_sso_target_url
7
+ t.text :idp_cert
8
+ end
9
+
10
+ add_index :identity_providers, :domain
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class AddProviderIdToUsers < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :users, :identity_provider_id, :uuid
4
+
5
+ add_foreign_key :users, :identity_providers
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEnterpriseAccounts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :enterprise_accounts, id: :uuid do |t|
4
+ t.string :domain, null: false
5
+ t.uuid :external_uuid
6
+ t.integer :external_int_id
7
+ t.string :external_id
8
+ end
9
+
10
+ add_index :enterprise_accounts, :domain, unique: true
11
+
12
+ add_reference :identity_providers, :enterprise_account, type: :uuid, index: true
13
+ add_reference :users, :enterprise_account, type: :uuid, index: true
14
+ end
15
+ end