Skip to content

Commit

Permalink
Merge pull request #53 from MidwestAccessCoalition/migrate-GET_verify…
Browse files Browse the repository at this point in the history
…_authy_installation

Migrate DeviseAuthyController#GET_verify_authy_installation
  • Loading branch information
wwahammy authored Apr 11, 2024
2 parents 43f8a12 + 517822b commit 23d44f7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions app/controllers/devise/devise_authy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def POST_disable_authy
end

def GET_verify_authy_installation
if resource_class.authy_enable_qr_code
response = Authy::API.request_qr_code(id: resource.authy_id)
@authy_qr_code = response.qr_code
if resource.mfa_config.qr_code_uri
uri = resource.mfa_config.qr_code_uri
# from https://gist.github.com/bf4/5188994
@verify_qr_code = RQRCode::QRCode.new(uri).as_png(size: 200).to_data_url
end
render :verify_authy_installation
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/verify_authy_installation.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2><%= I18n.t('authy_verify_installation_title', scope: 'devise') %></h2>

<% if @authy_qr_code %>
<%= image_tag @authy_qr_code, :size => '256x256', :alt => I18n.t('authy_qr_code_alt', scope: 'devise') %>
<% if @verify_qr_code %>
<%= image_tag @verify_qr_code, :size => '200x200', :alt => I18n.t('authy_qr_code_alt', scope: 'devise') %>
<p><%= I18n.t('authy_qr_code_instructions', scope: 'devise') %></p>
<% end %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/verify_authy_installation.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%h2= I18n.t('authy_verify_installation_title', scope: 'devise')

- if @authy_qr_code
= image_tag @authy_qr_code, :size => '256x256', :alt => I18n.t('authy_qr_code_alt', scope: 'devise')
- if @verify_qr_code
= image_tag @verify_qr_code, :size => '256x256', :alt => I18n.t('authy_qr_code_alt', scope: 'devise')
%p= I18n.t('authy_qr_code_instructions', scope: 'devise')

= verify_authy_installation_form do
Expand Down
1 change: 1 addition & 0 deletions devise-authy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "devise", ">= 4.0.0"
spec.add_dependency "authy", "~> 3.0"
spec.add_dependency "twilio-ruby", "~> 6.9"
spec.add_dependency "rqrcode", "~> 2.0"

spec.add_development_dependency "appraisal", "~> 2.2"
spec.add_development_dependency "bundler", ">= 1.16"
Expand Down
1 change: 1 addition & 0 deletions lib/devise-authy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'active_support/core_ext/integer/time'
require 'devise'
require 'authy'
require 'rqrcode'
require_relative './twilio-verify-client'

module Devise
Expand Down
9 changes: 4 additions & 5 deletions spec/controllers/devise_authy_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,13 @@
Devise.authy_enable_qr_code = false
end

it "should hit API for a QR code" do
expect(Authy::API).to receive(:request_qr_code).with(
:id => user.authy_id
).and_return(double("Authy::Request", :qr_code => 'https://example.com/qr.png'))
it "should generate a QR code" do

user.mfa_config.update(qr_code_uri: 'https://example.com/qr.png')

get :GET_verify_authy_installation
expect(response).to render_template('verify_authy_installation')
expect(assigns[:authy_qr_code]).to eq('https://example.com/qr.png')
expect(assigns[:verify_qr_code]).to_not be_nil
end
end
end
Expand Down

0 comments on commit 23d44f7

Please sign in to comment.