aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth/Profile.pm4
-rw-r--r--perllib/FixMyStreet/Auth/GoogleAuth.pm27
4 files changed, 33 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 3e8c07fb0..42556d1df 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -13,7 +13,7 @@ use FixMyStreet::Email::Sender;
use FixMyStreet::PhotoStorage;
use Utils;
-use Auth::GoogleAuth;
+use FixMyStreet::Auth::GoogleAuth;
use Path::Tiny 'path';
use Try::Tiny;
use Text::CSV;
@@ -528,7 +528,7 @@ sub check_2fa {
my ($c, $secret32) = @_;
if (my $code = $c->get_param('2fa_code')) {
- my $auth = Auth::GoogleAuth->new;
+ my $auth = FixMyStreet::Auth::GoogleAuth->new;
return 1 if $auth->verify($code, 2, $secret32);
$c->stash->{incorrect_code} = 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 8265506ab..4660f45dd 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -364,8 +364,8 @@ sub signup_2fa : Private {
}
if ($action eq 'activate') {
- my $auth = Auth::GoogleAuth->new;
- $c->stash->{qr_code} = $auth->qr_code($secret, $user->email, 'FixMyStreet');
+ my $auth = FixMyStreet::Auth::GoogleAuth->new;
+ $c->stash->{qr_code} = $auth->qr_code($secret, $user->email, $c->cobrand->base_url);
$c->stash->{secret32} = $auth->secret32;
$c->stash->{stage} = 'activate';
}
diff --git a/perllib/FixMyStreet/App/Controller/Auth/Profile.pm b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
index a1bbfc570..a89c6f539 100644
--- a/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
@@ -216,8 +216,8 @@ sub generate_token : Path('/auth/generate_token') {
}
if ($action eq 'activate') {
- my $auth = Auth::GoogleAuth->new;
- $c->stash->{qr_code} = $auth->qr_code($secret, $c->user->email, 'FixMyStreet');
+ my $auth = FixMyStreet::Auth::GoogleAuth->new;
+ $c->stash->{qr_code} = $auth->qr_code($secret, $c->user->email, $c->cobrand->base_url);
$c->stash->{secret32} = $auth->secret32;
$c->stash->{stage} = 'activate';
}
diff --git a/perllib/FixMyStreet/Auth/GoogleAuth.pm b/perllib/FixMyStreet/Auth/GoogleAuth.pm
new file mode 100644
index 000000000..ffe58b2dd
--- /dev/null
+++ b/perllib/FixMyStreet/Auth/GoogleAuth.pm
@@ -0,0 +1,27 @@
+package FixMyStreet::Auth::GoogleAuth;
+
+use parent 'Auth::GoogleAuth';
+
+use strict;
+use warnings;
+use Image::PNG::QRCode 'qrpng';
+use URI;
+
+# Overridden to return a data: URI of the image
+sub qr_code {
+ my $self = shift;
+ my ( $secret32, $key_id, $issuer, $return_otpauth ) = @_;
+
+ # Make issuer a bit nicer to read
+ $issuer =~ s{https?://}{};
+
+ my $otpauth = $self->SUPER::qr_code($secret32, $key_id, $issuer, 1);
+ return $otpauth if $return_otpauth;
+
+ my $u = URI->new('data:');
+ $u->media_type('image/png');
+ $u->data(qrpng(text => $otpauth));
+ return $u;
+}
+
+1;