line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Class representing an asynchronous Duo authentication. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This class wraps the transaction ID returned by Duo from an asynchronous |
4
|
|
|
|
|
|
|
# authentication and provides a method to long-poll the status of that |
5
|
|
|
|
|
|
|
# authentication attempt. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Net::Duo::Auth::Async 1.01; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
69
|
use 5.014; |
|
3
|
|
|
|
|
9
|
|
10
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
67
|
|
11
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
77
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
14
|
use Net::Duo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
707
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# All dies are of constructed objects, which perlcritic misdiagnoses. |
16
|
|
|
|
|
|
|
## no critic (ErrorHandling::RequireCarping) |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Create a new Net::Duo::Auth::Async object from the transaction ID and a |
19
|
|
|
|
|
|
|
# Net::Duo object. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# $class - Class of object to create |
22
|
|
|
|
|
|
|
# $duo - Net::Duo object to use for calls |
23
|
|
|
|
|
|
|
# $id - The transaction ID of an asynchronous transaction |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# Returns: Newly-created object |
26
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem creating the object |
27
|
|
|
|
|
|
|
sub new { |
28
|
2
|
|
|
2
|
1
|
8
|
my ($class, $duo, $id) = @_; |
29
|
2
|
|
|
|
|
8
|
my $self = { _duo => $duo, id => $id }; |
30
|
2
|
|
|
|
|
5
|
bless($self, $class); |
31
|
2
|
|
|
|
|
8
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Return the transaction ID. |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# $self - The Net::Duo::Auth::Async object |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# Returns: The underlying transaction ID |
39
|
|
|
|
|
|
|
sub id { |
40
|
3
|
|
|
3
|
1
|
1581
|
my ($self) = @_; |
41
|
3
|
|
|
|
|
15
|
return $self->{id}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Check on the current status of an asynchronous authentication. This uses |
45
|
|
|
|
|
|
|
# long polling, meaning that the call returns for every status change, |
46
|
|
|
|
|
|
|
# but does not otherwise have a timeout. |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# $self - The Net::Duo::Auth::Async object |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# Returns: Scalar context: the current status |
51
|
|
|
|
|
|
|
# List context: list of current status and reference to hash of data |
52
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on failure |
53
|
|
|
|
|
|
|
sub status { |
54
|
2
|
|
|
2
|
1
|
5
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Make the Duo call. |
57
|
2
|
|
|
|
|
6
|
my $data = { txid => $self->{id} }; |
58
|
2
|
|
|
|
|
4
|
my $uri = '/auth/v2/auth_status'; |
59
|
2
|
|
|
|
|
8
|
my $result = $self->{_duo}->call_json('GET', $uri, $data); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Ensure the response included a result field. |
62
|
2
|
50
|
|
|
|
7
|
if (!defined($result->{result})) { |
63
|
0
|
|
|
|
|
0
|
my $error = 'no authentication result from Duo'; |
64
|
0
|
|
|
|
|
0
|
die Net::Duo::Exception->protocol($error, $result); |
65
|
|
|
|
|
|
|
} |
66
|
2
|
|
|
|
|
4
|
my $status = $result->{result}; |
67
|
2
|
|
|
|
|
5
|
delete $result->{result}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Return the result as appropriate for context. |
70
|
2
|
100
|
|
|
|
13
|
return wantarray ? ($status, $result) : $status; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |