diff --git a/Gemfile b/Gemfile index c422a910..85521327 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,8 @@ gem 'turbo-rails', '~> 2.0' # For authentication. gem 'devise', '~> 4.9', '>= 4.9.2' gem 'devise-encryptable', '~> 0.2.0' +gem 'omniauth', '~> 2.1' +gem 'omniauth-rails_csrf_protection', '~> 1.0' # For pagination UI. gem 'will_paginate', '~> 4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 4e5d4d7a..30025cdc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,6 +164,7 @@ GEM temple (>= 0.8.2) thor tilt + hashie (5.0.0) http_accept_language (2.1.1) httparty (0.21.0) mini_mime (>= 1.0.0) @@ -214,6 +215,13 @@ GEM nokogiri (1.16.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) + omniauth (2.1.2) + hashie (>= 3.4.6) + rack (>= 2.2.3) + rack-protection + omniauth-rails_csrf_protection (1.0.1) + actionpack (>= 4.2) + omniauth (~> 2.0) openssl (3.2.0) orm_adapter (0.5.0) parallel (1.24.0) @@ -239,6 +247,9 @@ GEM rack (>= 1.0, < 4) rack-mini-profiler (3.3.1) rack (>= 1.2.0) + rack-protection (4.0.0) + base64 (>= 0.1.0) + rack (>= 3.0.0, < 4) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -382,6 +393,8 @@ DEPENDENCIES memory_profiler (~> 1.0) mysql2 (~> 0.5.5) nokogiri (~> 1.15, >= 1.15.3) + omniauth (~> 2.1) + omniauth-rails_csrf_protection (~> 1.0) parallel (~> 1.23) rack-attack (~> 6.7) rack-mini-profiler (~> 3.1) diff --git a/app/models/auth_user.rb b/app/models/auth_user.rb index f649257c..7de07bc1 100644 --- a/app/models/auth_user.rb +++ b/app/models/auth_user.rb @@ -2,7 +2,7 @@ class AuthUser < AuthRecord self.table_name = 'users' devise :database_authenticatable, :encryptable, :registerable, :validatable, - :rememberable, :trackable, :recoverable + :rememberable, :trackable, :recoverable, omniauthable: [:developer] validates :name, presence: true, uniqueness: {case_sensitive: false}, length: {maximum: 20} diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index e852d897..6306b365 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -273,7 +273,7 @@ Devise.setup do |config| # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :developer # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/db/openneo_id_migrate/20240313200849_add_omniauth_fields_to_users.rb b/db/openneo_id_migrate/20240313200849_add_omniauth_fields_to_users.rb new file mode 100644 index 00000000..89369425 --- /dev/null +++ b/db/openneo_id_migrate/20240313200849_add_omniauth_fields_to_users.rb @@ -0,0 +1,6 @@ +class AddOmniauthFieldsToUsers < ActiveRecord::Migration[7.1] + def change + add_column :users, :provider, :string + add_column :users, :uid, :string + end +end diff --git a/db/openneo_id_schema.rb b/db/openneo_id_schema.rb index 930f0827..4a630c3b 100644 --- a/db/openneo_id_schema.rb +++ b/db/openneo_id_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_08_07_005748) do +ActiveRecord::Schema[7.1].define(version: 2024_03_13_200849) do create_table "users", id: { type: :integer, unsigned: true }, charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.string "name", limit: 20, null: false t.string "encrypted_password", limit: 64, null: false @@ -29,6 +29,8 @@ ActiveRecord::Schema[7.1].define(version: 2023_08_07_005748) do t.datetime "updated_at", precision: nil t.datetime "reset_password_sent_at", precision: nil t.datetime "remember_created_at" + t.string "provider" + t.string "uid" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true diff --git a/vendor/cache/hashie-5.0.0.gem b/vendor/cache/hashie-5.0.0.gem new file mode 100644 index 00000000..ae9aae4a Binary files /dev/null and b/vendor/cache/hashie-5.0.0.gem differ diff --git a/vendor/cache/omniauth-2.1.2.gem b/vendor/cache/omniauth-2.1.2.gem new file mode 100644 index 00000000..ba7a07b1 Binary files /dev/null and b/vendor/cache/omniauth-2.1.2.gem differ diff --git a/vendor/cache/omniauth-rails_csrf_protection-1.0.1.gem b/vendor/cache/omniauth-rails_csrf_protection-1.0.1.gem new file mode 100644 index 00000000..98607a34 Binary files /dev/null and b/vendor/cache/omniauth-rails_csrf_protection-1.0.1.gem differ diff --git a/vendor/cache/rack-protection-4.0.0.gem b/vendor/cache/rack-protection-4.0.0.gem new file mode 100644 index 00000000..2ad0f428 Binary files /dev/null and b/vendor/cache/rack-protection-4.0.0.gem differ