Browse Source

Hard fork and rename project

master
baarkerlounger 3 years ago
parent
commit
e136495836
  1. 21
      .codeclimate.yml
  2. 28
      .travis.yml
  3. 4
      README.md
  4. 4
      app/controllers/devise/two_factor_authentication_controller.rb
  5. 16
      devise2fa.gemspec
  6. 18
      lib/devise2fa.rb
  7. 6
      lib/devise2fa/controllers/helpers.rb
  8. 6
      lib/devise2fa/hooks/two_factor_authenticatable.rb
  9. 2
      lib/devise2fa/models/two_factor_authenticatable.rb
  10. 14
      lib/devise2fa/orm/active_record.rb
  11. 4
      lib/devise2fa/rails.rb
  12. 0
      lib/devise2fa/routes.rb
  13. 2
      lib/devise2fa/schema.rb
  14. 3
      lib/devise2fa/version.rb
  15. 14
      lib/two_factor_authentication/orm/active_record.rb
  16. 3
      lib/two_factor_authentication/version.rb
  17. 5
      spec/rails_app/config/application.rb
  18. 37
      spec/rails_app/db/schema.rb
  19. 2
      spec/support/controller_helper.rb
  20. 4
      spec/support/features_spec_helper.rb

21
.codeclimate.yml

@ -1,21 +0,0 @@
engines:
brakeman:
enabled: true
duplication:
enabled: true
config:
languages:
- ruby
# mass_threshold: 30
exclude_paths:
- 'spec/**/*'
fixme:
enabled: true
rubocop:
enabled: true
ratings:
paths:
- app/**
- lib/**
- '**.rb'

28
.travis.yml

@ -1,28 +0,0 @@
language: ruby
env:
- "RAILS_VERSION=4.2"
- "RAILS_VERSION=5.2"
- "RAILS_VERSION=master"
rvm:
- 2.3.8
- 2.4.5
- 2.5.3
matrix:
fast_finish: true
allow_failures:
- env: "RAILS_VERSION=master"
include:
- rvm: 2.2
env: RAILS_VERSION=4.2
before_install:
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
- gem install bundler -v '< 2'
before_script:
- bundle exec rake app:db:setup
script: bundle exec rake spec

4
README.md

@ -1,6 +1,8 @@
# Two factor authentication for Devise # Two factor authentication for Devise
[![Build Status](https://github.com/devise2fa/two_factor_authentication/actions/workflows/tests.yml/badge.svg?branch=master&event=push)](https://github.com/devise2fa/two_factor_authentication/actions/workflows/tests.yml) [![Build Status](https://github.com/devise2fa/two_factor_authentication/actions/workflows/tests.yml/badge.svg?branch=master&event=push)](https://github.com/baarkerlounger/two_factor_authentication/actions/workflows/tests.yml)
This is a fork of [Houdini/two_factor_authentication](https://github.com/Houdini/two_factor_authentication) to enable development to continue as that repository no longer seems to be actively developed. With thanks to all contributors.
## Features ## Features

4
app/controllers/devise/two_factor_authentication_controller.rb

@ -27,7 +27,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController
def after_two_factor_success_for(resource) def after_two_factor_success_for(resource)
set_remember_two_factor_cookie(resource) set_remember_two_factor_cookie(resource)
warden.session(resource_name)[TwoFactorAuthentication::NEED_AUTHENTICATION] = false warden.session(resource_name)[Devise2Fa::NEED_AUTHENTICATION] = false
# For compatability with devise versions below v4.2.0 # For compatability with devise versions below v4.2.0
# https://github.com/plataformatec/devise/commit/2044fffa25d781fcbaf090e7728b48b65c854ccb # https://github.com/plataformatec/devise/commit/2044fffa25d781fcbaf090e7728b48b65c854ccb
if respond_to?(:bypass_sign_in) if respond_to?(:bypass_sign_in)
@ -45,7 +45,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController
expires_seconds = resource.class.remember_otp_session_for_seconds expires_seconds = resource.class.remember_otp_session_for_seconds
if expires_seconds && expires_seconds > 0 if expires_seconds && expires_seconds > 0
cookies.signed[TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] = { cookies.signed[Devise2Fa::REMEMBER_TFA_COOKIE_NAME] = {
value: "#{resource.class}-#{resource.public_send(Devise.second_factor_resource_id)}", value: "#{resource.class}-#{resource.public_send(Devise.second_factor_resource_id)}",
expires: expires_seconds.seconds.from_now expires: expires_seconds.seconds.from_now
} }

16
two_factor_authentication.gemspec → devise2fa.gemspec

@ -1,14 +1,14 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__) $:.push File.expand_path("../lib", __FILE__)
require "two_factor_authentication/version" require "devise2fa/version"
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "two_factor_authentication" s.name = "devise2fa"
s.version = TwoFactorAuthentication::VERSION.dup s.version = Devise2Fa::VERSION.dup
s.authors = ["Dmitrii Golub"] s.authors = ["baarkerlounger"]
s.email = ["dmitrii.golub@gmail.com"] s.email = ["baarkerlounger@protonmail.com"]
s.homepage = "https://github.com/Houdini/two_factor_authentication" s.homepage = "https://github.com/devise2fa/devise2fa"
s.summary = %q{Two factor authentication plugin for devise} s.summary = %q{Two factor authentication plugin for devise forked from Houdini/two_factor_authentication}
s.license = "MIT" s.license = "MIT"
s.description = <<-EOF s.description = <<-EOF
### Features ### ### Features ###
@ -18,7 +18,7 @@ Gem::Specification.new do |s|
* your own sms logic * your own sms logic
EOF EOF
s.rubyforge_project = "two_factor_authentication" s.rubyforge_project = "devise2fa"
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

18
lib/two_factor_authentication.rb → lib/devise2fa.rb

@ -1,4 +1,4 @@
require 'two_factor_authentication/version' require 'devise2fa/version'
require 'devise' require 'devise'
require 'active_support/concern' require 'active_support/concern'
require "active_model" require "active_model"
@ -34,19 +34,19 @@ module Devise
@@delete_cookie_on_logout = false @@delete_cookie_on_logout = false
end end
module TwoFactorAuthentication module Devise2Fa
NEED_AUTHENTICATION = 'need_two_factor_authentication' NEED_AUTHENTICATION = 'need_two_factor_authentication'
REMEMBER_TFA_COOKIE_NAME = "remember_tfa" REMEMBER_TFA_COOKIE_NAME = "remember_tfa"
autoload :Schema, 'two_factor_authentication/schema' autoload :Schema, 'devise2fa/schema'
module Controllers module Controllers
autoload :Helpers, 'two_factor_authentication/controllers/helpers' autoload :Helpers, 'devise2fa/controllers/helpers'
end end
end end
Devise.add_module :two_factor_authenticatable, :model => 'two_factor_authentication/models/two_factor_authenticatable', :controller => :two_factor_authentication, :route => :two_factor_authentication Devise.add_module :two_factor_authenticatable, :model => 'devise2fa/models/two_factor_authenticatable', :controller => :two_factor_authentication, :route => :two_factor_authentication
require 'two_factor_authentication/orm/active_record' if defined?(ActiveRecord::Base) require 'devise2fa/orm/active_record' if defined?(ActiveRecord::Base)
require 'two_factor_authentication/routes' require 'devise2fa/routes'
require 'two_factor_authentication/models/two_factor_authenticatable' require 'devise2fa/models/two_factor_authenticatable'
require 'two_factor_authentication/rails' require 'devise2fa/rails'

6
lib/two_factor_authentication/controllers/helpers.rb → lib/devise2fa/controllers/helpers.rb

@ -1,4 +1,4 @@
module TwoFactorAuthentication module Devise2Fa
module Controllers module Controllers
module Helpers module Helpers
extend ActiveSupport::Concern extend ActiveSupport::Concern
@ -12,7 +12,7 @@ module TwoFactorAuthentication
def handle_two_factor_authentication def handle_two_factor_authentication
unless devise_controller? unless devise_controller?
Devise.mappings.keys.flatten.any? do |scope| Devise.mappings.keys.flatten.any? do |scope|
if signed_in?(scope) and warden.session(scope)[TwoFactorAuthentication::NEED_AUTHENTICATION] if signed_in?(scope) and warden.session(scope)[Devise2Fa::NEED_AUTHENTICATION]
handle_failed_second_factor(scope) handle_failed_second_factor(scope)
end end
end end
@ -47,7 +47,7 @@ module Devise
module Controllers module Controllers
module Helpers module Helpers
def is_fully_authenticated? def is_fully_authenticated?
!session["warden.user.user.session"].try(:[], TwoFactorAuthentication::NEED_AUTHENTICATION) !session["warden.user.user.session"].try(:[], Devise2Fa::NEED_AUTHENTICATION)
end end
end end
end end

6
lib/two_factor_authentication/hooks/two_factor_authenticatable.rb → lib/devise2fa/hooks/two_factor_authenticatable.rb

@ -1,17 +1,17 @@
Warden::Manager.after_authentication do |user, auth, options| Warden::Manager.after_authentication do |user, auth, options|
if auth.env["action_dispatch.cookies"] if auth.env["action_dispatch.cookies"]
expected_cookie_value = "#{user.class}-#{user.public_send(Devise.second_factor_resource_id)}" expected_cookie_value = "#{user.class}-#{user.public_send(Devise.second_factor_resource_id)}"
actual_cookie_value = auth.env["action_dispatch.cookies"].signed[TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] actual_cookie_value = auth.env["action_dispatch.cookies"].signed[Devise2Fa::REMEMBER_TFA_COOKIE_NAME]
bypass_by_cookie = actual_cookie_value == expected_cookie_value bypass_by_cookie = actual_cookie_value == expected_cookie_value
end end
if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie
if auth.session(options[:scope])[TwoFactorAuthentication::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request) if auth.session(options[:scope])[Devise2Fa::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request)
user.send_new_otp if user.send_new_otp_after_login? user.send_new_otp if user.send_new_otp_after_login?
end end
end end
end end
Warden::Manager.before_logout do |user, auth, _options| Warden::Manager.before_logout do |user, auth, _options|
auth.cookies.delete TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME if Devise.delete_cookie_on_logout auth.cookies.delete Devise2Fa::REMEMBER_TFA_COOKIE_NAME if Devise.delete_cookie_on_logout
end end

2
lib/two_factor_authentication/models/two_factor_authenticatable.rb → lib/devise2fa/models/two_factor_authenticatable.rb

@ -1,4 +1,4 @@
require 'two_factor_authentication/hooks/two_factor_authenticatable' require 'devise2fa/hooks/two_factor_authenticatable'
require 'rotp' require 'rotp'
require 'encryptor' require 'encryptor'

14
lib/devise2fa/orm/active_record.rb

@ -0,0 +1,14 @@
require "active_record"
module Devise2Fa
module Orm
module ActiveRecord
module Schema
# include Devise2Fa::Schema
end
end
end
end
ActiveRecord::ConnectionAdapters::Table.send :include, Devise2Fa::Orm::ActiveRecord::Schema
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise2Fa::Orm::ActiveRecord::Schema

4
lib/two_factor_authentication/rails.rb → lib/devise2fa/rails.rb

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

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

2
lib/two_factor_authentication/schema.rb → lib/devise2fa/schema.rb

@ -1,4 +1,4 @@
module TwoFactorAuthentication module Devise2Fa
module Schema module Schema
def second_factor_attempts_count def second_factor_attempts_count
apply_devise_schema :second_factor_attempts_count, Integer, :default => 0 apply_devise_schema :second_factor_attempts_count, Integer, :default => 0

3
lib/devise2fa/version.rb

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

14
lib/two_factor_authentication/orm/active_record.rb

@ -1,14 +0,0 @@
require "active_record"
module TwoFactorAuthentication
module Orm
module ActiveRecord
module Schema
include TwoFactorAuthentication::Schema
end
end
end
end
ActiveRecord::ConnectionAdapters::Table.send :include, TwoFactorAuthentication::Orm::ActiveRecord::Schema
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TwoFactorAuthentication::Orm::ActiveRecord::Schema

3
lib/two_factor_authentication/version.rb

@ -1,3 +0,0 @@
module TwoFactorAuthentication
VERSION = "2.2.0".freeze
end

5
spec/rails_app/config/application.rb

@ -6,7 +6,7 @@ require "action_mailer/railtie"
require "sprockets/railtie" require "sprockets/railtie"
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
require "two_factor_authentication" require "devise2fa"
module Dummy module Dummy
class Application < Rails::Application class Application < Rails::Application
@ -47,6 +47,8 @@ module Dummy
# like if you have constraints or database-specific column types # like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql # config.active_record.schema_format = :sql
config.active_record.legacy_connection_handling = false
# Enable the asset pipeline # Enable the asset pipeline
config.assets.enabled = true config.assets.enabled = true
@ -60,4 +62,3 @@ module Dummy
config.secret_key_base = 'secretvalue' config.secret_key_base = 'secretvalue'
end end
end end

37
spec/rails_app/db/schema.rb

@ -2,29 +2,28 @@
# of editing this file, please use the migrations feature of Active Record to # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
# #
# Note that this schema.rb definition is the authoritative source for your # This file is the source Rails uses to define your schema when running `bin/rails
# database schema. If you need to create the application database on another # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# system, you should be using db:schema:load, not running all the migrations # be faster and is potentially less error prone than running all of your
# from scratch. The latter is a flawed and unsustainable approach (the more migrations # migrations from scratch. Old migrations may fail to apply correctly if those
# you'll amass, the slower it'll run and the greater likelihood for issues). # migrations use external dependencies or application code.
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2016_02_09_032439) do ActiveRecord::Schema[7.0].define(version: 2016_02_09_032439) do
create_table "admins", force: :cascade do |t| create_table "admins", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at", precision: nil
t.datetime "remember_created_at" t.datetime "remember_created_at", precision: nil
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at", precision: nil
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at", null: false t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", null: false t.datetime "updated_at", precision: nil, null: false
t.index ["email"], name: "index_admins_on_email", unique: true t.index ["email"], name: "index_admins_on_email", unique: true
t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
end end
@ -33,15 +32,15 @@ ActiveRecord::Schema.define(version: 2016_02_09_032439) do
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at", precision: nil
t.datetime "remember_created_at" t.datetime "remember_created_at", precision: nil
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at", precision: nil
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at", null: false t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", null: false t.datetime "updated_at", precision: nil, null: false
t.integer "second_factor_attempts_count", default: 0 t.integer "second_factor_attempts_count", default: 0
t.string "nickname", limit: 64 t.string "nickname", limit: 64
t.string "encrypted_otp_secret_key" t.string "encrypted_otp_secret_key"

2
spec/support/controller_helper.rb

@ -2,7 +2,7 @@ module ControllerHelper
def sign_in(user = create_user('not_encrypted')) def sign_in(user = create_user('not_encrypted'))
allow(warden).to receive(:authenticated?).with(:user).and_return(true) allow(warden).to receive(:authenticated?).with(:user).and_return(true)
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
warden.session(:user)[TwoFactorAuthentication::NEED_AUTHENTICATION] = true warden.session(:user)[Devise2Fa::NEED_AUTHENTICATION] = true
end end
end end

4
spec/support/features_spec_helper.rb

@ -20,11 +20,11 @@ module FeaturesSpecHelper
end end
def set_tfa_cookie value def set_tfa_cookie value
set_cookie TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME, value set_cookie Devise2Fa::REMEMBER_TFA_COOKIE_NAME, value
end end
def get_tfa_cookie def get_tfa_cookie
get_cookie TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME get_cookie Devise2Fa::REMEMBER_TFA_COOKIE_NAME
end end
end end

Loading…
Cancel
Save