From 50b4d8eda4a602558daedda044b60d4b5e9e249b Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 5 Jul 2022 11:26:57 +0100 Subject: [PATCH] Rename gem --- Gemfile | 1 + .../two_factor_authentication_controller.rb | 4 ++-- ...=> devise_two_factor_authentication.gemspec | 10 +++++----- lib/devise2fa/rails.rb | 7 ------- lib/devise2fa/version.rb | 3 --- ....rb => devise_two_factor_authentication.rb} | 18 +++++++++--------- .../controllers/helpers.rb | 6 +++--- .../hooks/two_factor_authenticatable.rb | 6 +++--- .../models/two_factor_authenticatable.rb | 2 +- .../orm/active_record.rb | 0 lib/devise_two_factor_authentication/rails.rb | 7 +++++++ .../routes.rb | 0 .../schema.rb | 2 +- .../version.rb | 3 +++ spec/rails_app/config/application.rb | 2 +- spec/support/controller_helper.rb | 2 +- spec/support/features_spec_helper.rb | 4 ++-- 17 files changed, 39 insertions(+), 38 deletions(-) rename devise2fa.gemspec => devise_two_factor_authentication.gemspec (80%) delete mode 100644 lib/devise2fa/rails.rb delete mode 100644 lib/devise2fa/version.rb rename lib/{devise2fa.rb => devise_two_factor_authentication.rb} (61%) rename lib/{devise2fa => devise_two_factor_authentication}/controllers/helpers.rb (88%) rename lib/{devise2fa => devise_two_factor_authentication}/hooks/two_factor_authenticatable.rb (63%) rename lib/{devise2fa => devise_two_factor_authentication}/models/two_factor_authenticatable.rb (98%) rename lib/{devise2fa => devise_two_factor_authentication}/orm/active_record.rb (100%) create mode 100644 lib/devise_two_factor_authentication/rails.rb rename lib/{devise2fa => devise_two_factor_authentication}/routes.rb (100%) rename lib/{devise2fa => devise_two_factor_authentication}/schema.rb (95%) create mode 100644 lib/devise_two_factor_authentication/version.rb diff --git a/Gemfile b/Gemfile index dd64f57..730cea0 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ end group :test, :development do gem 'pry' + gem 'rubocop' gem 'sprockets-rails' gem 'sqlite3' end diff --git a/app/controllers/devise/two_factor_authentication_controller.rb b/app/controllers/devise/two_factor_authentication_controller.rb index 490eeda..87ba4fd 100644 --- a/app/controllers/devise/two_factor_authentication_controller.rb +++ b/app/controllers/devise/two_factor_authentication_controller.rb @@ -27,7 +27,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController def after_two_factor_success_for(resource) set_remember_two_factor_cookie(resource) - warden.session(resource_name)[Devise2Fa::NEED_AUTHENTICATION] = false + warden.session(resource_name)[DeviseTwoFactorAuthentication::NEED_AUTHENTICATION] = false # For compatability with devise versions below v4.2.0 # https://github.com/plataformatec/devise/commit/2044fffa25d781fcbaf090e7728b48b65c854ccb if respond_to?(:bypass_sign_in) @@ -45,7 +45,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController expires_seconds = resource.class.remember_otp_session_for_seconds if expires_seconds && expires_seconds > 0 - cookies.signed[Devise2Fa::REMEMBER_TFA_COOKIE_NAME] = { + cookies.signed[DeviseTwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] = { value: "#{resource.class}-#{resource.public_send(Devise.second_factor_resource_id)}", expires: expires_seconds.seconds.from_now } diff --git a/devise2fa.gemspec b/devise_two_factor_authentication.gemspec similarity index 80% rename from devise2fa.gemspec rename to devise_two_factor_authentication.gemspec index 11a78ac..0920d56 100644 --- a/devise2fa.gemspec +++ b/devise_two_factor_authentication.gemspec @@ -1,13 +1,13 @@ # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) -require "devise2fa/version" +require "devise_two_factor_authentication/version" Gem::Specification.new do |s| - s.name = "devise2fa" - s.version = Devise2Fa::VERSION.dup + s.name = "devise_two_factor_authentication" + s.version = DeviseTwoFactorAuthentication::VERSION.dup s.authors = ["baarkerlounger"] s.email = ["baarkerlounger@protonmail.com"] - s.homepage = "https://github.com/devise2fa/devise2fa" + s.homepage = "https://github.com/devise2fa/devise_two_factor_authentication" s.summary = %q{Two factor authentication plugin for devise forked from Houdini/two_factor_authentication} s.license = "MIT" s.description = <<-EOF @@ -18,7 +18,7 @@ Gem::Specification.new do |s| * your own sms logic EOF - s.rubyforge_project = "devise2fa" + s.rubyforge_project = "devise_two_factor_authentication" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/lib/devise2fa/rails.rb b/lib/devise2fa/rails.rb deleted file mode 100644 index 5b544d7..0000000 --- a/lib/devise2fa/rails.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Devise2Fa - class Engine < ::Rails::Engine - ActiveSupport.on_load(:action_controller) do - include Devise2Fa::Controllers::Helpers - end - end -end diff --git a/lib/devise2fa/version.rb b/lib/devise2fa/version.rb deleted file mode 100644 index 8e43036..0000000 --- a/lib/devise2fa/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Devise2Fa - VERSION = "3.0.0".freeze -end diff --git a/lib/devise2fa.rb b/lib/devise_two_factor_authentication.rb similarity index 61% rename from lib/devise2fa.rb rename to lib/devise_two_factor_authentication.rb index 7eb687a..561acf6 100644 --- a/lib/devise2fa.rb +++ b/lib/devise_two_factor_authentication.rb @@ -1,4 +1,4 @@ -require 'devise2fa/version' +require 'devise_two_factor_authentication/version' require 'devise' require 'active_support/concern' require "active_model" @@ -34,19 +34,19 @@ module Devise @@delete_cookie_on_logout = false end -module Devise2Fa +module DeviseTwoFactorAuthentication NEED_AUTHENTICATION = 'need_two_factor_authentication' REMEMBER_TFA_COOKIE_NAME = "remember_tfa" - autoload :Schema, 'devise2fa/schema' + autoload :Schema, 'devise_two_factor_authentication/schema' module Controllers - autoload :Helpers, 'devise2fa/controllers/helpers' + autoload :Helpers, 'devise_two_factor_authentication/controllers/helpers' end end -Devise.add_module :two_factor_authenticatable, :model => 'devise2fa/models/two_factor_authenticatable', :controller => :two_factor_authentication, :route => :two_factor_authentication +Devise.add_module :two_factor_authenticatable, :model => 'devise_two_factor_authentication/models/two_factor_authenticatable', :controller => :two_factor_authentication, :route => :two_factor_authentication -require 'devise2fa/orm/active_record' if defined?(ActiveRecord::Base) -require 'devise2fa/routes' -require 'devise2fa/models/two_factor_authenticatable' -require 'devise2fa/rails' +require 'devise_two_factor_authentication/orm/active_record' if defined?(ActiveRecord::Base) +require 'devise_two_factor_authentication/routes' +require 'devise_two_factor_authentication/models/two_factor_authenticatable' +require 'devise_two_factor_authentication/rails' diff --git a/lib/devise2fa/controllers/helpers.rb b/lib/devise_two_factor_authentication/controllers/helpers.rb similarity index 88% rename from lib/devise2fa/controllers/helpers.rb rename to lib/devise_two_factor_authentication/controllers/helpers.rb index 73928b4..c5d9a98 100644 --- a/lib/devise2fa/controllers/helpers.rb +++ b/lib/devise_two_factor_authentication/controllers/helpers.rb @@ -1,4 +1,4 @@ -module Devise2Fa +module DeviseTwoFactorAuthentication module Controllers module Helpers extend ActiveSupport::Concern @@ -12,7 +12,7 @@ module Devise2Fa def handle_two_factor_authentication unless devise_controller? Devise.mappings.keys.flatten.any? do |scope| - if signed_in?(scope) and warden.session(scope)[Devise2Fa::NEED_AUTHENTICATION] + if signed_in?(scope) and warden.session(scope)[DeviseTwoFactorAuthentication::NEED_AUTHENTICATION] handle_failed_second_factor(scope) end end @@ -47,7 +47,7 @@ module Devise module Controllers module Helpers def is_fully_authenticated? - !session["warden.user.user.session"].try(:[], Devise2Fa::NEED_AUTHENTICATION) + !session["warden.user.user.session"].try(:[], DeviseTwoFactorAuthentication::NEED_AUTHENTICATION) end end end diff --git a/lib/devise2fa/hooks/two_factor_authenticatable.rb b/lib/devise_two_factor_authentication/hooks/two_factor_authenticatable.rb similarity index 63% rename from lib/devise2fa/hooks/two_factor_authenticatable.rb rename to lib/devise_two_factor_authentication/hooks/two_factor_authenticatable.rb index 4c4e070..c604b62 100644 --- a/lib/devise2fa/hooks/two_factor_authenticatable.rb +++ b/lib/devise_two_factor_authentication/hooks/two_factor_authenticatable.rb @@ -1,17 +1,17 @@ Warden::Manager.after_authentication do |user, auth, options| if auth.env["action_dispatch.cookies"] expected_cookie_value = "#{user.class}-#{user.public_send(Devise.second_factor_resource_id)}" - actual_cookie_value = auth.env["action_dispatch.cookies"].signed[Devise2Fa::REMEMBER_TFA_COOKIE_NAME] + actual_cookie_value = auth.env["action_dispatch.cookies"].signed[DeviseTwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] bypass_by_cookie = actual_cookie_value == expected_cookie_value end if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie - if auth.session(options[:scope])[Devise2Fa::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request) + if auth.session(options[:scope])[DeviseTwoFactorAuthentication::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request) user.send_new_otp if user.send_new_otp_after_login? end end end Warden::Manager.before_logout do |user, auth, _options| - auth.cookies.delete Devise2Fa::REMEMBER_TFA_COOKIE_NAME if Devise.delete_cookie_on_logout + auth.cookies.delete DeviseTwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME if Devise.delete_cookie_on_logout end diff --git a/lib/devise2fa/models/two_factor_authenticatable.rb b/lib/devise_two_factor_authentication/models/two_factor_authenticatable.rb similarity index 98% rename from lib/devise2fa/models/two_factor_authenticatable.rb rename to lib/devise_two_factor_authentication/models/two_factor_authenticatable.rb index d345dbe..176c1e6 100644 --- a/lib/devise2fa/models/two_factor_authenticatable.rb +++ b/lib/devise_two_factor_authentication/models/two_factor_authenticatable.rb @@ -1,4 +1,4 @@ -require 'devise2fa/hooks/two_factor_authenticatable' +require 'devise_two_factor_authentication/hooks/two_factor_authenticatable' require 'rotp' require 'encryptor' diff --git a/lib/devise2fa/orm/active_record.rb b/lib/devise_two_factor_authentication/orm/active_record.rb similarity index 100% rename from lib/devise2fa/orm/active_record.rb rename to lib/devise_two_factor_authentication/orm/active_record.rb diff --git a/lib/devise_two_factor_authentication/rails.rb b/lib/devise_two_factor_authentication/rails.rb new file mode 100644 index 0000000..95f6ca6 --- /dev/null +++ b/lib/devise_two_factor_authentication/rails.rb @@ -0,0 +1,7 @@ +module DeviseTwoFactorAuthentication + class Engine < ::Rails::Engine + ActiveSupport.on_load(:action_controller) do + include DeviseTwoFactorAuthentication::Controllers::Helpers + end + end +end diff --git a/lib/devise2fa/routes.rb b/lib/devise_two_factor_authentication/routes.rb similarity index 100% rename from lib/devise2fa/routes.rb rename to lib/devise_two_factor_authentication/routes.rb diff --git a/lib/devise2fa/schema.rb b/lib/devise_two_factor_authentication/schema.rb similarity index 95% rename from lib/devise2fa/schema.rb rename to lib/devise_two_factor_authentication/schema.rb index 3294553..41c69f2 100644 --- a/lib/devise2fa/schema.rb +++ b/lib/devise_two_factor_authentication/schema.rb @@ -1,4 +1,4 @@ -module Devise2Fa +module DeviseTwoFactorAuthentication module Schema def second_factor_attempts_count apply_devise_schema :second_factor_attempts_count, Integer, :default => 0 diff --git a/lib/devise_two_factor_authentication/version.rb b/lib/devise_two_factor_authentication/version.rb new file mode 100644 index 0000000..c2963b7 --- /dev/null +++ b/lib/devise_two_factor_authentication/version.rb @@ -0,0 +1,3 @@ +module DeviseTwoFactorAuthentication + VERSION = "3.0.0".freeze +end diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb index 88193a2..934c6b6 100644 --- a/spec/rails_app/config/application.rb +++ b/spec/rails_app/config/application.rb @@ -6,7 +6,7 @@ require "action_mailer/railtie" require "sprockets/railtie" Bundler.require(*Rails.groups) -require "devise2fa" +require "devise_two_factor_authentication" module Dummy class Application < Rails::Application diff --git a/spec/support/controller_helper.rb b/spec/support/controller_helper.rb index 6f1d701..39862f4 100644 --- a/spec/support/controller_helper.rb +++ b/spec/support/controller_helper.rb @@ -2,7 +2,7 @@ module ControllerHelper def sign_in(user = create_user('not_encrypted')) allow(warden).to receive(:authenticated?).with(:user).and_return(true) allow(controller).to receive(:current_user).and_return(user) - warden.session(:user)[Devise2Fa::NEED_AUTHENTICATION] = true + warden.session(:user)[DeviseTwoFactorAuthentication::NEED_AUTHENTICATION] = true end end diff --git a/spec/support/features_spec_helper.rb b/spec/support/features_spec_helper.rb index 592f5c6..e247993 100644 --- a/spec/support/features_spec_helper.rb +++ b/spec/support/features_spec_helper.rb @@ -20,11 +20,11 @@ module FeaturesSpecHelper end def set_tfa_cookie value - set_cookie Devise2Fa::REMEMBER_TFA_COOKIE_NAME, value + set_cookie DeviseTwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME, value end def get_tfa_cookie - get_cookie Devise2Fa::REMEMBER_TFA_COOKIE_NAME + get_cookie DeviseTwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME end end