Browse Source

Rename gem

master
baarkerlounger 3 years ago
parent
commit
50b4d8eda4
  1. 1
      Gemfile
  2. 4
      app/controllers/devise/two_factor_authentication_controller.rb
  3. 10
      devise_two_factor_authentication.gemspec
  4. 7
      lib/devise2fa/rails.rb
  5. 3
      lib/devise2fa/version.rb
  6. 18
      lib/devise_two_factor_authentication.rb
  7. 6
      lib/devise_two_factor_authentication/controllers/helpers.rb
  8. 6
      lib/devise_two_factor_authentication/hooks/two_factor_authenticatable.rb
  9. 2
      lib/devise_two_factor_authentication/models/two_factor_authenticatable.rb
  10. 0
      lib/devise_two_factor_authentication/orm/active_record.rb
  11. 7
      lib/devise_two_factor_authentication/rails.rb
  12. 0
      lib/devise_two_factor_authentication/routes.rb
  13. 2
      lib/devise_two_factor_authentication/schema.rb
  14. 3
      lib/devise_two_factor_authentication/version.rb
  15. 2
      spec/rails_app/config/application.rb
  16. 2
      spec/support/controller_helper.rb
  17. 4
      spec/support/features_spec_helper.rb

1
Gemfile

@ -24,6 +24,7 @@ end
group :test, :development do
gem 'pry'
gem 'rubocop'
gem 'sprockets-rails'
gem 'sqlite3'
end

4
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
}

10
devise2fa.gemspec → 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")

7
lib/devise2fa/rails.rb

@ -1,7 +0,0 @@
module Devise2Fa
class Engine < ::Rails::Engine
ActiveSupport.on_load(:action_controller) do
include Devise2Fa::Controllers::Helpers
end
end
end

3
lib/devise2fa/version.rb

@ -1,3 +0,0 @@
module Devise2Fa
VERSION = "3.0.0".freeze
end

18
lib/devise2fa.rb → 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'

6
lib/devise2fa/controllers/helpers.rb → 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

6
lib/devise2fa/hooks/two_factor_authenticatable.rb → 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

2
lib/devise2fa/models/two_factor_authenticatable.rb → 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'

0
lib/devise2fa/orm/active_record.rb → lib/devise_two_factor_authentication/orm/active_record.rb

7
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

0
lib/devise2fa/routes.rb → lib/devise_two_factor_authentication/routes.rb

2
lib/devise2fa/schema.rb → 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

3
lib/devise_two_factor_authentication/version.rb

@ -0,0 +1,3 @@
module DeviseTwoFactorAuthentication
VERSION = "3.0.0".freeze
end

2
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

2
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

4
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

Loading…
Cancel
Save