File Coverage

lib/LWP/Authen/OAuth2/ServiceProvider/Line/AccessToken.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 3 33.3
total 25 27 92.5


line stmt bran cond sub pod time code
1             package LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken;
2              
3             # ABSTRACT: Line AccessToken
4             our $VERSION = '0.19'; # VERSION
5              
6 1     1   57779 use strict;
  1         11  
  1         24  
7 1     1   4 use warnings;
  1         2  
  1         22  
8 1     1   346 use parent 'LWP::Authen::OAuth2::AccessToken::Bearer';
  1         256  
  1         5  
9              
10             our $REFRESH_PERIOD = 864000; # 10 days. https://devdocs.line.me/en/#refreshing-access-tokens
11              
12             # Line tokens can be refreshed until the refresh period is over.
13             sub should_refresh {
14 4     4 1 17 my ($self, @args) = @_;
15              
16 4 100       16 return 0 unless $self->SUPER::should_refresh(@args);
17              
18 3         8 my $refresh_expires_time = $self->expires_time + $REFRESH_PERIOD;
19 3         6 my $refresh_token_valid = time < $refresh_expires_time;
20              
21 3         12 return $refresh_token_valid;
22             }
23              
24             # These are exposed for use with /oauth/verify and /oauth/revoke API requests
25 1     1 0 457 sub access_token { shift->{access_token} }
26 1     1 0 5 sub refresh_token { shift->{refresh_token} }
27              
28             1;
29              
30             __END__