| 1 | package WWW::JSON::Role::Authentication::OAuth1; | ||||||||||
| 2 | 8 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 8 | ▶ | use Net::OAuth; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 8 | $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; | |||||||||
| 6 | 8 | requires 'authentication'; | |||||||||
| 7 | 8 | requires 'ua'; | |||||||||
| 8 | |||||||||||
| 9 | sub _validate_OAuth1 { | ||||||||||
| 10 | 1 | ▶ | my ( $self, $auth ) = @_; | ||||||||
|
Subroutine
_validate_OAuth1: called CC=3 SCAR=11.2
| |||||||||||
| 11 | 1 | for (qw/consumer_key consumer_secret token token_secret/) { | |||||||||
| 12 | die "Required parameter $_ missing for " . __PACKAGE__ . " authentication" | ||||||||||
| 13 | 4 | ▶ | unless exists( $auth->{$_} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | } | ||||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | sub _auth_OAuth1 { | ||||||||||
| 18 | 2 | ▶ | my ( $self, $auth, $req) = @_; | ||||||||
|
Subroutine
_auth_OAuth1: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | my $q = URI->new; | |||||||||
| 20 | # FIXME if we're sending a JSON payload we need to decode instead of this | ||||||||||
| 21 | 2 | $q->query($req->content); | |||||||||
| 22 | 2 | 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 | $request->sign; | |||||||||
| 32 | 2 | $request->to_authorization_header; | |||||||||
| 33 | 2 | $req->header( Authorization => $request->to_authorization_header ); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub _nonce { | ||||||||||
| 37 | 2 | ▶ | my @chars = ( 'A' .. 'Z', 'a' .. 'z', '0' .. '9' ); | ||||||||
|
Subroutine
_nonce: called CC=2 SCAR=6.9
| |||||||||||
| 38 | 2 | my $nonce = time; | |||||||||
| 39 | 2 | for ( 1 .. 15 ) { | |||||||||
| 40 | 30 | $nonce .= $chars[ rand @chars ]; | |||||||||
| 41 | } | ||||||||||
| 42 | 2 | return $nonce; | |||||||||
| 43 | } | ||||||||||
| 44 | 8 | 1; | |||||||||