diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-11-22 19:07:26 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-11-23 14:52:02 +0000 |
commit | 5ee12f1525fd928cb7af7558b61a2d0a001155bf (patch) | |
tree | 1f6cedb8abbde5ffa049289aa4995a9ad51e4486 /perllib/FixMyStreet/Auth/GoogleAuth.pm | |
parent | 09026f609ce28860d555967e0f5d7cd833fb20d0 (diff) |
Switch to internal QR code generator.
Diffstat (limited to 'perllib/FixMyStreet/Auth/GoogleAuth.pm')
-rw-r--r-- | perllib/FixMyStreet/Auth/GoogleAuth.pm | 27 |
1 files changed, 27 insertions, 0 deletions
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; |