OAuth2/AccessToken.pm

filter: Statementstmt 21.5% 20 / 93 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 14.7% 5 / 34 Podpod 96.5% 28 / 29 totaltotal 27.4% 53 / 193 CC 16 SCAR 23.3
CC
16
Cov
16%
init
42.0
access_token
20.0
expired
12.0
CRAP 10.3
« OAuth2/Profile.pm ↑ Summary OAuth2/Profile/WebServer.pm »
1 # Copyrights 2013-2019 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Net-OAuth2. Meta-POD processed
6 # with OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Net::OAuth2::AccessToken;
10 4 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 $VERSION = '0.67';
12  
13 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 our $VERSION; # to be able to test in devel environment
17  
18 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use JSON::MaybeXS qw/encode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # Attributes to be saved to preserve the session.
22 4 my @session = qw/access_token token_type refresh_token expires_at
23 scope state auto_refresh/;
24  
25 # This class name is kept for backwards compatibility: a better name
26 # would have been: Net::OAuth2::Session, with a ::Token::Bearer split-off.
27  
28 # In the future, most of this functionality will probably need to be
29 # split-off in a base class ::Token, to be shared with a new extension
30 # which supports HTTP-MAC tokens as proposed by ietf dragt
31 # http://datatracker.ietf.org/doc/draft-ietf-oauth-v2-http-mac/
32  
33  
34 0 ▶sub new(@) { my $class = shift; (bless {}, $class)->init({@_}) }
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
35  
36 sub init($)
37 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=6 SCAR=37.4
Pod undocumented
38  
39 $self->{NOA_expires_at} = $args->{expires_at}
40 0 ▶ || ($args->{expires_in} ? time()+$args->{expires_in} : undef);
Branch: 1 branch
BranchTrueFalseTotal
$args->{'expires_in'} ? : 0 0 0
Condition0%0/3
$args->{'expires_at'} || ($args->{'expires_in'} ? time + $args->{'expires_in'} : undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'expires_at'} || ($args->{'expires_in'} ? time + $args->{'expires_in'} : undef)
$args->{'expires_at'} ($args->{'expires_in'} ? time + $args->{'expires_in'} : undef)
Truth table0%0/3
A || B
A= $args->{'expires_at'}B= ($args->{'expires_in'} ? time + $args->{'expires_in'} : undef)
ABresult
1X1
011
000
41  
42 # client is the pre-v0.50 name
43 my $profile = $self->{NOA_profile} = $args->{profile} || $args->{client}
44 0 ▶ or croak "::AccessToken needs profile object";
Branch: 1 branch
BranchTrueFalseTotal
my $profile = $self->{"NOA_profile"} = $args->{"profile"} || $args->{"client"} or croak("::AccessToken needs profile object") 0 0 0
Condition0%0/3
$args->{'profile'} || $args->{'client'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'profile'} || $args->{'client'}
$args->{'profile'} $args->{'client'}
Truth table0%0/3
A || B
A= $args->{'profile'}B= $args->{'client'}
ABresult
1X1
011
000
45  
46 0 $self->{NOA_access_token} = $args->{access_token};
47 0 $self->{NOA_refresh_token} = $args->{refresh_token};
48 0 $self->{NOA_refresh_always}= $args->{refresh_always};
49 0 $self->{NOA_scope} = $args->{scope};
50 0 $self->{NOA_state} = $args->{state};
51 0 $self->{NOA_hd} = $args->{hd};
52 0 $self->{NOA_token_type} = $args->{token_type};
53 0 $self->{NOA_auto_refresh} = $args->{auto_refresh};
54 0 $self->{NOA_changed} = $args->{changed};
55  
56 0 $self->{NOA_error} = $args->{error};
57 0 $self->{NOA_error_uri} = $args->{error_uri};
58 0 ▶ $self->{NOA_error_descr} = $args->{error_description} || $args->{error};
Condition0%0/3
$args->{'error_description'} || $args->{'error'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'error_description'} || $args->{'error'}
$args->{'error_description'} $args->{'error'}
Truth table0%0/3
A || B
A= $args->{'error_description'}B= $args->{'error'}
ABresult
1X1
011
000
59  
60 0 $self->{NOA_attr} = $args;
61 0 $self;
62 }
63  
64  
65 sub session_thaw($%)
66 0 ▶{ my ($class, $session) = (shift, shift);
Subroutine session_thaw: not called CC=1 SCAR=6.9
Pod documented
67 # we can use $session->{net_oauth2_version} to upgrade the info
68 0 $class->new(%$session, @_);
69 }
70  
71 #--------------
72  
73 0 ▶sub token_type() {shift->{NOA_token_type}}
Subroutine token_type: not called CC=1 SCAR=6.9
Pod documented
74 0 ▶sub scope() {shift->{NOA_scope}}
Subroutine scope: not called CC=1 SCAR=6.9
Pod documented
75 0 ▶sub state() {shift->{NOA_state}}
Subroutine state: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub hd() {shift->{NOA_hd}}
Subroutine hd: not called CC=1 SCAR=6.9
Pod documented
77 0 ▶sub profile() {shift->{NOA_profile}}
Subroutine profile: not called CC=1 SCAR=6.9
Pod documented
78  
79  
80 0 ▶sub attribute($) { $_[0]->{NOA_attr}{$_[1]} }
Subroutine attribute: not called CC=1 SCAR=6.9
Pod documented
81  
82  
83 sub changed(;$)
84 0 ▶{ my $s = shift; @_ ? $s->{NOA_changed} = shift : $s->{NOA_changed} }
Subroutine changed: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
85  
86  
87 sub access_token()
88 0 ▶{ my $self = shift;
Subroutine access_token: not called CC=4 SCAR=30.0
Pod documented
89  
90 0 ▶ if($self->expired)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->expired) { } 0 0 0
elsif ($self->refresh_always) { } 0 0 0
91 0 { delete $self->{NOA_access_token};
92 0 $self->{NOA_changed} = 1;
93 0 ▶ $self->refresh if $self->auto_refresh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->auto_refresh 0 0 0
94 }
95 elsif($self->refresh_always)
96 0 { $self->refresh;
97 }
98  
99 0 $self->{NOA_access_token};
100 }
101  
102 #---------------
103  
104 0 ▶sub error() {shift->{NOA_error}}
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
105 0 ▶sub error_uri() {shift->{NOA_error_uri}}
Subroutine error_uri: not called CC=1 SCAR=6.9
Pod documented
106 0 ▶sub error_description() {shift->{NOA_error_descr}}
Subroutine error_description: not called CC=1 SCAR=6.9
Pod documented
107  
108 #---------------
109  
110 0 ▶sub refresh_token() {shift->{NOA_refresh_token}}
Subroutine refresh_token: not called CC=1 SCAR=6.9
Pod documented
111 0 ▶sub refresh_always() {shift->{NOA_refresh_always}}
Subroutine refresh_always: not called CC=1 SCAR=6.9
Pod documented
112 0 ▶sub auto_refresh() {shift->{NOA_auto_refresh}}
Subroutine auto_refresh: not called CC=1 SCAR=6.9
Pod documented
113  
114  
115 0 ▶sub expires_at() { shift->{NOA_expires_at} }
Subroutine expires_at: not called CC=1 SCAR=6.9
Pod documented
116  
117  
118 0 ▶sub expires_in() { shift->expires_at - time() }
Subroutine expires_in: not called CC=1 SCAR=6.9
Pod documented
119  
120  
121 sub expired(;$)
122 0 ▶{ my ($self, $after) = @_;
Subroutine expired: not called CC=3 SCAR=24.8
Pod documented
123 0 ▶ my $when = $self->expires_at or return;
Branch: 1 branch
BranchTrueFalseTotal
my $when = $self->expires_at or return 0 0 0
124 0 ▶ $after = 15 unless defined $after;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $after 0 0 0
125 0 $when < time() + $after;
126 }
127  
128  
129 sub update_token($$$;$)
130 0 ▶{ my ($self, $token, $type, $exp, $refresh) = @_;
Subroutine update_token: not called CC=3 SCAR=24.8
Pod documented
131 0 $self->{NOA_access_token} = $token;
132 0 ▶ $self->{NOA_token_type} = $type if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 0 0 0
133 0 $self->{NOA_expires_at} = $exp;
134  
135 0 ▶ $self->{NOA_refresh_token} = $refresh
Branch: 1 branch
BranchTrueFalseTotal
if defined $refresh 0 0 0
136 if defined $refresh;
137  
138 0 $token;
139 }
140  
141 #--------------
142  
143 sub to_json()
144 0 ▶{ my $self = shift;
Subroutine to_json: not called CC=1 SCAR=6.9
Pod documented
145 0 encode_json $self->session_freeze;
146 }
147 4 *to_string = \&to_json; # until v0.50
148  
149  
150 sub session_freeze(%)
151 0 ▶{ my ($self, %args) = @_;
Subroutine session_freeze: not called CC=3 SCAR=24.8
Pod documented
152 0 my %data = (net_oauth2_version => $VERSION);
153 0 ▶ defined $self->{"NOA_$_"} && ($data{$_} = $self->{"NOA_$_"}) for @session;
Branch: 1 branch
BranchTrueFalseTotal
defined $$self{"NOA_$_"} and $data{$_} = $$self{"NOA_$_"} 0 0 0
154 0 $self->changed(0);
155 0 \%data;
156 }
157  
158  
159 sub refresh()
160 0 ▶{ my $self = shift;
Subroutine refresh: not called CC=1 SCAR=6.9
Pod documented
161 0 $self->profile->update_access_token($self);
162 }
163  
164 #--------------
165  
166 0 ▶sub request{ my $s = shift; $s->profile->request_auth($s, @_) }
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
167 0 ▶sub get { my $s = shift; $s->profile->request_auth($s, 'GET', @_) }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
168 0 ▶sub post { my $s = shift; $s->profile->request_auth($s, 'POST', @_) }
Subroutine post: not called CC=1 SCAR=6.9
Pod documented
169 0 ▶sub delete { my $s = shift; $s->profile->request_auth($s, 'DELETE', @_) }
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
170 0 ▶sub put { my $s = shift; $s->profile->request_auth($s, 'PUT', @_) }
Subroutine put: not called CC=1 SCAR=6.9
Pod documented
171  
172 4 1;
« OAuth2/Profile.pm ↑ Summary OAuth2/Profile/WebServer.pm »