| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::JSON::Role::Authentication::OAuth1; | 
| 2 | 8 |  |  | 8 |  | 3962 | use Moo::Role; | 
|  | 8 |  |  |  |  | 16 |  | 
|  | 8 |  |  |  |  | 171 |  | 
| 3 | 8 |  |  | 8 |  | 6932 | use Net::OAuth; | 
|  | 8 |  |  |  |  | 5141 |  | 
|  | 8 |  |  |  |  | 250 |  | 
| 4 | 8 |  |  | 8 |  | 53 | use URI; | 
|  | 8 |  |  |  |  | 13 |  | 
|  | 8 |  |  |  |  | 2811 |  | 
| 5 |  |  |  |  |  |  | $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; | 
| 6 |  |  |  |  |  |  | requires 'authentication'; | 
| 7 |  |  |  |  |  |  | requires 'ua'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub _validate_OAuth1 { | 
| 10 | 1 |  |  | 1 |  | 2 | my ( $self, $auth ) = @_; | 
| 11 | 1 |  |  |  |  | 2 | for (qw/consumer_key consumer_secret token token_secret/) { | 
| 12 | 4 | 50 |  |  |  | 26 | die "Required parameter $_ missing for " . __PACKAGE__ . " authentication" | 
| 13 |  |  |  |  |  |  | unless exists( $auth->{$_} ); | 
| 14 |  |  |  |  |  |  | } | 
| 15 |  |  |  |  |  |  | } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub _auth_OAuth1 { | 
| 18 | 2 |  |  | 2 |  | 2 | my ( $self, $auth, $req) = @_; | 
| 19 | 2 |  |  |  |  | 7 | my $q = URI->new; | 
| 20 |  |  |  |  |  |  | # FIXME if we're sending a JSON payload we need to decode instead of this | 
| 21 | 2 |  |  |  |  | 88 | $q->query($req->content); | 
| 22 | 2 |  |  |  |  | 51 | my $request = Net::OAuth->request("protected resource")->new( | 
| 23 |  |  |  |  |  |  | %$auth, | 
| 24 |  |  |  |  |  |  | request_url      => $req->uri, | 
| 25 |  |  |  |  |  |  | request_method   => $req->method, | 
| 26 |  |  |  |  |  |  | signature_method => 'HMAC-SHA1', | 
| 27 |  |  |  |  |  |  | timestamp        => time(), | 
| 28 |  |  |  |  |  |  | nonce            => _nonce(), | 
| 29 |  |  |  |  |  |  | extra_params     => {$q->query_form}, | 
| 30 |  |  |  |  |  |  | ); | 
| 31 | 2 |  |  |  |  | 517 | $request->sign; | 
| 32 | 2 |  |  |  |  | 10997 | $request->to_authorization_header; | 
| 33 | 2 |  |  |  |  | 1480 | $req->header( Authorization => $request->to_authorization_header ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub _nonce { | 
| 37 | 2 |  |  | 2 |  | 7904 | my @chars = ( 'A' .. 'Z', 'a' .. 'z', '0' .. '9' ); | 
| 38 | 2 |  |  |  |  | 3 | my $nonce = time; | 
| 39 | 2 |  |  |  |  | 5 | for ( 1 .. 15 ) { | 
| 40 | 30 |  |  |  |  | 67 | $nonce .= $chars[ rand @chars ]; | 
| 41 |  |  |  |  |  |  | } | 
| 42 | 2 |  |  |  |  | 17 | return $nonce; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | 1; |