From bb2dd725f4fb5218db5a5eff9f00424e2a8c3f35 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:51:28 +0000 Subject: [PATCH 1/6] Create tests.yml --- .github/workflows/tests.yml | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1f82dc8 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,42 @@ +name: 'CI/CD Pipeline' + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + + test: + name: Test + runs-on: ubuntu-latest + + env: + RAILS_ENV: test + GEMFILE_RUBY_VERSION: 3.0.3 + + # Rails verifies the time zone in DB is the same as the time zone of the Rails app + TZ: "Europe/London" + + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.3 + # runs 'bundle install' and caches installed gems automatically + bundler-cache: true + + - name: Run tests + run: | + bundle exec rake spec + From c2237dedb89b1fc53101cec536e57912049c5412 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:52:50 +0000 Subject: [PATCH 2/6] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index f4f91d1..ea372ba 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Two factor authentication for Devise -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Houdini/two_factor_authentication?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -[![Build Status](https://travis-ci.org/Houdini/two_factor_authentication.svg?branch=master)](https://travis-ci.org/Houdini/two_factor_authentication) +[![Build Status](https://github.com/baarkerlounger/two_factor_authentication/actions/workflows/tests.yml/badge.svg?branch=master&event=push)](https://github.com/baarkerlounger/two_factor_authentication/actions/workflows/tests.yml) [![Code Climate](https://codeclimate.com/github/Houdini/two_factor_authentication.svg)](https://codeclimate.com/github/Houdini/two_factor_authentication) ## Features From aa74eb531da6f918bfe6d4a3648ae193ef053188 Mon Sep 17 00:00:00 2001 From: Recker Swartz Date: Fri, 18 Feb 2022 11:11:59 +0530 Subject: [PATCH 3/6] Update two_factor_authentication.rb --- lib/two_factor_authentication.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/two_factor_authentication.rb b/lib/two_factor_authentication.rb index 7b1bbbc..87c1740 100644 --- a/lib/two_factor_authentication.rb +++ b/lib/two_factor_authentication.rb @@ -32,6 +32,12 @@ module Devise mattr_accessor :delete_cookie_on_logout @@delete_cookie_on_logout = false + + mattr_accessor :issuer + @@issuer = '' + + mattr_accessor :logo_url + @@logo_url = '' end module TwoFactorAuthentication From cfc235320f1611408773b2139ce87271eabbf846 Mon Sep 17 00:00:00 2001 From: Recker Swartz Date: Fri, 18 Feb 2022 11:23:25 +0530 Subject: [PATCH 4/6] Update two_factor_authenticatable.rb --- .../models/two_factor_authenticatable.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/two_factor_authentication/models/two_factor_authenticatable.rb b/lib/two_factor_authentication/models/two_factor_authenticatable.rb index d23cae8..a3c422d 100644 --- a/lib/two_factor_authentication/models/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/models/two_factor_authenticatable.rb @@ -16,7 +16,8 @@ module Devise ::Devise::Models.config( self, :max_login_attempts, :allowed_otp_drift_seconds, :otp_length, :remember_otp_session_for_seconds, :otp_secret_encryption_key, - :direct_otp_length, :direct_otp_valid_for, :totp_timestamp, :delete_cookie_on_logout + :direct_otp_length, :direct_otp_valid_for, :totp_timestamp, :delete_cookie_on_logout, + :issuer, :issuer_name, :logo_url ) end @@ -53,6 +54,8 @@ module Devise options[:digits] ||= options[:otp_length] || self.class.otp_length raise "provisioning_uri called with no otp_secret_key set" if totp_secret.nil? account ||= email if respond_to?(:email) + options[:issuer] ||= options[:issuer_name] unless options[:issuer_name].blank? + options[:image] ||= options[:logo_url] unless options[:logo_url].blank? ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) end From 3a2e91a5fa14ee28404645d496adaacfe1bac2e2 Mon Sep 17 00:00:00 2001 From: Recker Swartz Date: Fri, 18 Feb 2022 11:23:58 +0530 Subject: [PATCH 5/6] Update two_factor_authentication.rb --- lib/two_factor_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/two_factor_authentication.rb b/lib/two_factor_authentication.rb index 87c1740..0600366 100644 --- a/lib/two_factor_authentication.rb +++ b/lib/two_factor_authentication.rb @@ -33,7 +33,7 @@ module Devise mattr_accessor :delete_cookie_on_logout @@delete_cookie_on_logout = false - mattr_accessor :issuer + mattr_accessor :issuer_name @@issuer = '' mattr_accessor :logo_url From fc88ef7ed64a0adb5e6f0c80cc2036895b5d45e0 Mon Sep 17 00:00:00 2001 From: Recker Swartz Date: Fri, 18 Feb 2022 14:58:27 +0530 Subject: [PATCH 6/6] Update two_factor_authenticatable.rb --- .../models/two_factor_authenticatable.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/two_factor_authentication/models/two_factor_authenticatable.rb b/lib/two_factor_authentication/models/two_factor_authenticatable.rb index a3c422d..eb6c064 100644 --- a/lib/two_factor_authentication/models/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/models/two_factor_authenticatable.rb @@ -52,11 +52,16 @@ module Devise def provisioning_uri(account = nil, options = {}) totp_secret = options[:otp_secret_key] || otp_secret_key options[:digits] ||= options[:otp_length] || self.class.otp_length - raise "provisioning_uri called with no otp_secret_key set" if totp_secret.nil? + raise 'provisioning_uri called with no otp_secret_key set' if totp_secret.nil? + account ||= email if respond_to?(:email) - options[:issuer] ||= options[:issuer_name] unless options[:issuer_name].blank? - options[:image] ||= options[:logo_url] unless options[:logo_url].blank? - ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) + options[:issuer] ||= self.class.issuer_name if self.class.issuer_name.present? + if self.class.logo_url.blank? + ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) + else + image = "&image=#{self.class.logo_url}" + ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) + image + end end def need_two_factor_authentication?(request)