File Coverage

lib/LWP/Authen/OAuth2/AccessToken/Bearer.pm
Criterion Covered Total %
statement 12 18 66.6
branch 0 2 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod n/a
total 16 28 57.1


line stmt bran cond sub pod time code
1             package LWP::Authen::OAuth2::AccessToken::Bearer;
2              
3             # ABSTRACT: Bearer access tokens for OAuth2
4             our $VERSION = '0.18'; # VERSION
5              
6 2     2   60619 use strict;
  2         12  
  2         48  
7 2     2   8 use warnings;
  2         4  
  2         51  
8 2     2   12 use base "LWP::Authen::OAuth2::AccessToken";
  2         3  
  2         875  
9 2     2   1102 use Storable qw(dclone);
  2         5416  
  2         362  
10              
11             sub _request {
12 0     0     my ($self, $oauth2, $request, @rest) = @_;
13 0           my $actual_request = dclone($request);
14             # This is where we sign it.
15 0           $actual_request->header('Authorization' => "Bearer $self->{access_token}");
16 0           my $response = $oauth2->user_agent->request($actual_request, @rest);
17              
18             # One would hope for a 401 status, but the specification only requires
19             # this header. (Though recommends a 401 status.)
20 0 0 0       my $try_refresh = ($response->header("WWW-Authenticate")||'') =~ m/\binvalid_token\b/
21             || ($response->header('Client-Warning')||'') =~ m/Missing Authenticate header/ # Dwolla does not send WWW-Authenticate
22             || $response->content() =~ m/\bExpiredAccessToken\b/
23             ? 1 : 0;
24 0           return ($response, $try_refresh);
25             }
26              
27              
28             1;
29              
30             __END__