blib/lib/App/GoogleAuthUtils.pm

filter: Statementstmt 68.1% 15 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 65.5% 19 / 29 CC 2 SCAR 11.0
CC
2
Cov
62%
gen_google_auth_qrcode
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package App::GoogleAuthUtils;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 1 our $DATE = '2024-04-18'; # DATE
9 1 our $DIST = 'App-GoogleAuthUtils'; # DIST
10 1 our $VERSION = '0.006'; # VERSION
11  
12 1 our %SPEC;
13  
14 $SPEC{gen_google_auth_qrcode} = {
15 1 v => 1.1,
16 summary => 'Generate Google authenticator QR code (barcode) from a secret key',
17 description => <<'MARKDOWN',
18  
19 When generating a new 2FA token, you are usually presented with a secret key as
20 well as a 2D barcode (QR code) representation of this secret key. You are
21 advised to store the secret key and it's usually more convenient to store the
22 key code instead of the QR code. But when entering the secret key to the Google
23 authenticator app, it's often more convenient to scan the barcode instead of
24 typing or copy-pasting the code.
25  
26 This utility will convert the secret key code into bar code (opened in a
27 browser) so you can conveniently scan the bar code into your app.
28  
29 MARKDOWN
30 args => {
31 secret_key => {
32 schema => 'str*',
33 req => 1,
34 pos => 0,
35 },
36 issuer => {
37 schema => 'str*',
38 req => 1,
39 pos => 1,
40 },
41 account => {
42 schema => 'str*',
43 pos => 2,
44 },
45 output => {
46 schema => 'filename*',
47 cmdline_aliases => {o=>{}},
48 },
49 },
50 examples => [
51 {
52 args => {
53 secret_key => '6XDT6TSOGR5SCWKHXZ4DFBRXJVZGAKAW',
54 issuer => 'example.com',
55 },
56 test => 0,
57 'x.doc.show_result' => 0,
58 },
59 ],
60 };
61 0 ▶sub gen_google_auth_qrcode {
Subroutine gen_google_auth_qrcode: not called CC=2 SCAR=17.9
Pod documented
62 0 require File::Which;
63 0 require String::ShellQuote;
64 0 require URI::Encode;
65  
66 0 my %args = @_;
67  
68 my $url = join(
69 "",
70 "otpauth://totp/",
71 URI::Encode::uri_encode($args{issuer} . ($args{account} ? ":$args{account}" : "")),
72 "?secret=", $args{secret_key},
73 "&issuer=", $args{issuer},
74 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'account'} ? : 0 0 0
75  
76 0 require App::QRCodeUtils;
77 0 App::QRCodeUtils::gen_qrcode(text => $url);
78 }
79  
80 1 1;
81 # ABSTRACT: Utilities related to Google Authenticator
82  
83 __END__
↑ Summary