| 1 | package LWP::Authen::OAuth2::AccessToken::Bearer; | ||
| 2 | |||
| 3 | # ABSTRACT: Bearer access tokens for OAuth2 | ||
| 4 | our $VERSION = '0.19'; # VERSION | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use base "LWP::Authen::OAuth2::AccessToken"; | ||
| 9 | use Storable qw(dclone); | ||
| 10 | |||
| 11 | sub _request { | ||
| 12 | my ($self, $oauth2, $request, @rest) = @_; | ||
| 13 | my $actual_request = dclone($request); | ||
| 14 | # This is where we sign it. | ||
| 15 | $actual_request->header('Authorization' => "Bearer $self->{access_token}"); | ||
| 16 | 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 | 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 | return ($response, $try_refresh); | ||
| 25 | } | ||
| 26 | |||
| 27 | |||
| 28 | 1; | ||
| 29 | |||
| 30 | __END__ |