blib/lib/WWW/JSON/Role/Authentication/OAuth1.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 97.2% 35 / 36 SCAR 13.9
CC
4
Cov
97%
_validate_OAuth1
3.1
_nonce
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/WWW/JSON/Response.pm ↑ Summary blib/lib/WWW/JSON/Role/Authentication/Basic.pm »
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
BranchTrueFalseTotal
unless exists $auth->{$_} 0 4 4
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;
« blib/lib/WWW/JSON/Response.pm ↑ Summary blib/lib/WWW/JSON/Role/Authentication/Basic.pm »